Subscribe to User Events
Inherit from EasyManager.cs
using EasyCodeForVivox;
public class VivoxManager : EasyManager
{
}
Inject EasyEvents
using EasyCodeForVivox.Events;
using UnityEngine;
using Zenject;
public class VivoxEvents : MonoBehaviour
{
EasyEvents _events;
[Inject]
private void Initialize(EasyEvents events)
{
_events = events;
}
}
Dynamic Events
Make sure Dynamic Events are enabled

How to Subscribe to User Events in EasyCode
EasyManager
// User Event Callbacks
protected override void OnUserJoinedChannel(IParticipant participant)
{
base.OnUserJoinedChannel(participant);
}
protected override void OnUserLeftChannel(IParticipant participant)
{
base.OnUserLeftChannel(participant);
}
protected override void OnUserValuesUpdated(IParticipant participant)
{
base.OnUserValuesUpdated(participant);
}
EasyEvents
public void SubscribeToUserEvents()
{
_events.UserJoinedChannel += OnUserJoinedChannel;
_events.UserLeftChannel += OnUserLeftChannel;
_events.UserValuesUpdated += OnUserValuesUpdated;
}
public void UnsubscribeToUserEvents()
{
_events.UserJoinedChannel -= OnUserJoinedChannel;
_events.UserLeftChannel -= OnUserLeftChannel;
_events.UserValuesUpdated -= OnUserValuesUpdated;
}
protected virtual void OnUserJoinedChannel(IParticipant participant)
{
Debug.Log($"{participant.Account.DisplayName} Has Joined The Channel");
}
protected virtual void OnUserLeftChannel(IParticipant participant)
{
Debug.Log($"{participant.Account.DisplayName} Has Left The Channel");
}
protected virtual void OnUserValuesUpdated(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)]
private void OnUserJoinedChannel(IParticipant participant)
{
Debug.Log($"{participant.Account.DisplayName} Has Joined The Channel");
}
[UserEvent(UserStatus.UserLeftChannel)]
private void OnUserLeftChannel(IParticipant participant)
{
Debug.Log($"{participant.Account.DisplayName} Has Left The Channel");
}
[UserEvent(UserStatus.UserValuesUpdated)]
private void OnUserValuesUpdated(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 +=/-=
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)]
private async void OnUserJoinedChannelAsync(IParticipant participant)
{
Debug.Log($"{participant.Account.DisplayName} Has Joined The Channel");
await LoadPlayerData();
}
[UserEventAsync(UserStatus.UserLeftChannel)]
private async void OnUserLeftChannelAsync(IParticipant participant)
{
Debug.Log($"{participant.Account.DisplayName} Has Left The Channel");
await RemovePlayerFromLobby();
}
[UserEventAsync(UserStatus.UserValuesUpdated)]
private async void OnUserValuesUpdatedAsync(IParticipant participant)
{
Debug.Log($"{participant.Account.DisplayName} Has updated itself in the channel");
await SavePlayerData();
}
Last updated
Was this helpful?