Untitled
unknown
csharp
a year ago
2.2 kB
12
Indexable
```cs
private async Task OnLobbyJoinedOrCreated()
{
// Subscribe to lobby events
var callbacks = new LobbyEventCallbacks();
callbacks.LobbyChanged += OnLobbyChanged;
callbacks.PlayerLeft += OnPlayerLeft;
callbacks.PlayerJoined += OnPlayerJoined;
callbacks.DataChanged += OnDataChanged;
callbacks.KickedFromLobby += OnKickedFromLobby;
callbacks.LobbyDeleted += LobbyDeleted;
this.Log("Subscribing to lobby events... (ID: " + CurrentLobby.Id + ")");
try
{
await Lobbies.Instance.SubscribeToLobbyEventsAsync(CurrentLobby.Id, callbacks);
}
catch (LobbyServiceException ex)
{
switch (ex.Reason)
{
case LobbyExceptionReason.AlreadySubscribedToLobby: Debug.LogWarning($"Already subscribed to lobby. We did not need to try and subscribe again. Exception Message: {ex.Message}"); break;
case LobbyExceptionReason.SubscriptionToLobbyLostWhileBusy: Debug.LogError($"Subscription to lobby events was lost while it was busy trying to subscribe. Exception Message: {ex.Message}"); throw;
case LobbyExceptionReason.LobbyEventServiceConnectionError: Debug.LogError($"Failed to connect to lobby events. Exception Message: {ex.Message}"); throw;
default: throw;
}
}
}
#endregion Tasks
#region Internal Callbacks
private void OnKickedFromLobby()
{
Kicked?.Invoke();
}
private void OnDataChanged(Dictionary<string, ChangedOrRemovedLobbyValue<DataObject>> dictionary)
{
LobbyUpdated?.Invoke();
}
private void OnPlayerJoined(List<LobbyPlayerJoined> list)
{
PlayerJoined?.Invoke();
}
private void OnPlayerLeft(List<int> list)
{
PlayerLeft.Invoke();
}
private void OnLobbyChanged(ILobbyChanges changes)
{
LobbyUpdated?.Invoke();
}
```Editor is loading...
Leave a Comment