After enabling at least one region in the , 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 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.
PlayerAccount playerAccount = await PlayerAccount.GetMainAsync();
var rooms = playerAccount.Services.Rooms;
// Fetch all available Room regions from our Project
var availableRegions = await rooms.RefreshRegionsAsync();
if (availableRegions.Count == 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);
}
}
}