Rooms

After enabling at least one region in the Dashboard, you can use the CloudService.Rooms API to create Rooms and delete and fetch existing Rooms. After fetching an existing Room, you can join it via the CoherenceBridge.JoinRoom method:

using System.Collections.Generic;
using Coherence.Cloud;
using Coherence.Toolkit;
using System.Collections;
using UnityEngine;

public class AsyncRoomsExample : MonoBehaviour
{
    public CoherenceBridge bridge;

    private CloudService cloudService;

    void Start()
    {
        cloudService = bridge.CloudService;

        CreateAndJoinRoom();
    }

    private async void CreateAndJoinRoom()
    {
        // Wait for connection to be established with the coherence Cloud, authenticated as a Guest User.
        await cloudService.WaitForCloudServiceLoginAsync(1000);

        // Fetch all available Room regions from our Project
        IReadOnlyList<string> availableRegions = await cloudService.Rooms.RefreshRegionsAsync();

        // Create a room and join it for the first available region
        if (availableRegions.Count > 0)
        {
            CloudRoomsService roomsService = cloudService.Rooms.GetRoomServiceForRegion(availableRegions[0]);

            RoomData newRoom = await roomsService.CreateRoomAsync(RoomCreationOptions.Default);

            bridge.JoinRoom(newRoom);
        }
    }
}