Keeping the base methods are not necessary. They are simply Debug.Logs(). Feel free to delete them
// User Event CallbacksprotectedoverridevoidOnUserJoinedChannel(IParticipant participant){ base.OnUserJoinedChannel(participant);}protectedoverridevoidOnUserLeftChannel(IParticipant participant){ base.OnUserLeftChannel(participant);}protectedoverridevoidOnUserValuesUpdated(IParticipant participant){ base.OnUserValuesUpdated(participant);}
EasyEvents
publicvoidSubscribeToUserEvents(){_events.UserJoinedChannel+= OnUserJoinedChannel;_events.UserLeftChannel+= OnUserLeftChannel;_events.UserValuesUpdated+= OnUserValuesUpdated;}publicvoidUnsubscribeToUserEvents(){_events.UserJoinedChannel-= OnUserJoinedChannel;_events.UserLeftChannel-= OnUserLeftChannel;_events.UserValuesUpdated-= OnUserValuesUpdated;}protectedvirtualvoidOnUserJoinedChannel(IParticipant participant){Debug.Log($"{participant.Account.DisplayName} Has Joined The Channel");}protectedvirtualvoidOnUserLeftChannel(IParticipant participant){Debug.Log($"{participant.Account.DisplayName} Has Left The Channel");}protectedvirtualvoidOnUserValuesUpdated(IParticipant participant){Debug.Log($"{participant.Account.DisplayName} Has updated itself in the channel");}
Dynamic Events
Make sure the parameter in your method matches the event type. See what parameter is required for each User Event here. Dynamic events will dynamically invoke your method at runtime on every game object that has a dynamic event attribute. Because of this there is no need to Subscribe/Unsubscribe from events with the usual +=/-=
[UserEvent(UserStatus.UserJoinedChannel)]privatevoidOnUserJoinedChannel(IParticipant participant){Debug.Log($"{participant.Account.DisplayName} Has Joined The Channel");}[UserEvent(UserStatus.UserLeftChannel)]privatevoidOnUserLeftChannel(IParticipant participant){Debug.Log($"{participant.Account.DisplayName} Has Left The Channel");}[UserEvent(UserStatus.UserValuesUpdated)]privatevoidOnUserValuesUpdated(IParticipant participant){Debug.Log($"{participant.Account.DisplayName} Has updated itself in the channel");}
Dynamic Async Events
Make sure the parameter in your method matches the event type. See what parameter is required for each User Event here. Dynamic events will dynamically invoke your method at runtime on every game object that has a dynamic event attribute. Because of this there is no need to Subscribe/Unsubscribe from events with the usual +=/-=
Remember to use async void or async Task or else the event may run synchronously
More information on the methods called in any async method can be found here. Unity Gaming Services Examples. They are direct copies from Unity's docs. These are just examples and don't mimic real world use cases
[UserEventAsync(UserStatus.UserJoinedChannel)]privateasyncvoidOnUserJoinedChannelAsync(IParticipant participant){Debug.Log($"{participant.Account.DisplayName} Has Joined The Channel");awaitLoadPlayerData();}[UserEventAsync(UserStatus.UserLeftChannel)]privateasyncvoidOnUserLeftChannelAsync(IParticipant participant){Debug.Log($"{participant.Account.DisplayName} Has Left The Channel");awaitRemovePlayerFromLobby();}[UserEventAsync(UserStatus.UserValuesUpdated)]privateasyncvoidOnUserValuesUpdatedAsync(IParticipant participant){Debug.Log($"{participant.Account.DisplayName} Has updated itself in the channel");awaitSavePlayerData();}