Rooms

You can use the CloudService.Rooms API to create new Rooms or delete and fetch existing ones.

After logging in to coherence Cloud and fetching an existing Room, you can join it via the CoherenceBridge.JoinRoom method:

using Coherence.Cloud;
using Coherence.Toolkit;
using UnityEngine;

public class AsyncRoomsExample : MonoBehaviour
{
    async void Start()
    {
        // Wait until a player account has logged in to coherence Cloud.
        // The CoherenceCloudLogin component can be used for this.
        PlayerAccount playerAccount = await PlayerAccount.GetMainAsync();

        // Fetch information about regions available in our Project.
        var rooms = playerAccount.Services.Rooms;
        var regionsInfo = await rooms.RefreshRegionsInfoAsync();

        var availableRegions = regionsInfo.Regions;
        if (availableRegions.Length == 0)
        {
            return;
        }

        // Create a new room in the first available region
        var roomsService = rooms.GetRoomServiceForRegion(availableRegions[0]);
        var newRoom = await roomsService.CreateRoomAsync(RoomCreationOptions.Default);

        // Try finding a coherence Bridge that has 'Player Account' set to
        // 'Auto Login As Guest' or 'Main' and have it join the new room.
        if (CoherenceBridgeStore.TryGetBridge(playerAccount, out var bridge))
        {
            bridge.JoinRoom(newRoom);
        }
    }
}

Last updated

Was this helpful?