Mute / Unmute 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 Mute/Unmute Events in EasyCode

EasyManager

Keeping the base methods are not necessary. They are simply Debug.Logs(). Feel free to delete them

// User Audio Event Callbacks

protected override void OnUserMuted(IParticipant participant)
{
    base.OnUserMuted(participant);
}

protected override void OnUserUnmuted(IParticipant participant)
{
    base.OnUserUnmuted(participant);
}

protected override void OnUserNotSpeaking(IParticipant participant)
{
    base.OnUserNotSpeaking(participant);
}

protected override void OnUserSpeaking(IParticipant participant)
{
    base.OnUserSpeaking(participant);
}

protected override void OnLocalUserMuted()
{
    base.OnLocalUserMuted();
}

protected override void OnLocalUserUnmuted()
{
    base.OnLocalUserUnmuted();
}

protected override void OnCrossMuted(AccountId accountId)
{
    base.OnCrossMuted(accountId);
}

protected override void OnCrossUnmuted(AccountId accountId)
{
    base.OnCrossUnmuted(accountId);
}

EasyEvents

public void SubscribeToMuteEvents()
{
    _events.UserMuted += OnUserMuted;
    _events.UserUnmuted += OnUserUnmuted;
    _events.UserSpeaking += OnUserSpeaking;
    _events.UserNotSpeaking += OnUserNotSpeaking;
    _events.LocalUserMuted += OnLocalUserMuted;
    _events.LocalUserUnmuted += OnLocalUserUnmuted;
    _events.UserCrossMuted += OnCrossMuted;
    _events.UserCrossUnmuted += OnCrossUnmuted;
}

public void UnsubscribeToMuteEvents()
{
    _events.UserMuted -= OnUserMuted;
    _events.UserUnmuted -= OnUserUnmuted;
    _events.UserSpeaking -= OnUserSpeaking;
    _events.UserNotSpeaking -= OnUserNotSpeaking;
    _events.LocalUserMuted -= OnLocalUserMuted;
    _events.LocalUserUnmuted -= OnLocalUserUnmuted;
    _events.UserCrossMuted -= OnCrossMuted;
    _events.UserCrossUnmuted -= OnCrossUnmuted;
}



protected virtual void OnLocalUserMuted()
{
    Debug.Log("Local User is Muted");
}

protected virtual void OnLocalUserUnmuted()
{
    Debug.Log("Local User is Unmuted");
}

protected virtual void OnCrossMuted(AccountId accountId)
{
    Debug.Log($"Player {accountId.DisplayName} has been Cross Muted");
}

protected virtual void OnCrossUnmuted(AccountId accountId)
{
    Debug.Log($"Player {accountId.DisplayName} has been Cross Unmuted");
}

protected virtual void OnUserMuted(IParticipant participant)
{
    Debug.Log($"{participant.Account.DisplayName} Is Muted : (Muted For All : {participant.IsMutedForAll})");
}

protected virtual void OnUserUnmuted(IParticipant participant)
{
    Debug.Log($"{participant.Account.DisplayName} Is Unmuted : (Muted For All : {participant.IsMutedForAll})");
}

protected virtual void OnUserSpeaking(IParticipant participant)
{
    Debug.Log($"{participant.Account.DisplayName} Is Speaking : Audio Energy {participant.AudioEnergy}");
}

protected virtual void OnUserNotSpeaking(IParticipant participant)
{
    Debug.Log($"{participant.Account.DisplayName} Is Not Speaking");
}

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.LocalUserMuted)]
private void OnLocalUserMuted()
{
    Debug.Log("Local User is Muted");
}

[UserEvent(UserStatus.LocalUserUnmuted)]
private void OnLocalUserUnmuted()
{
    Debug.Log("Local User is Unmuted");
}

[UserEvent(UserStatus.UserCrossMuted)]
private void OnCrossMuted(AccountId accountId)
{
    Debug.Log($"Player {accountId.DisplayName} has been Cross Muted");
}

[UserEvent(UserStatus.UserCrossUnmuted)]
private void OnCrossUnmuted(AccountId accountId)
{
    Debug.Log($"Player {accountId.DisplayName} has been Cross Unmuted");
}

[UserEvent(UserStatus.UserMuted)]
private void OnUserMuted(IParticipant participant)
{
    Debug.Log($"{participant.Account.DisplayName} Is Muted : (Muted For All : {participant.IsMutedForAll})");
}

[UserEvent(UserStatus.UserUnmuted)]
private void OnUserUnmuted(IParticipant participant)
{
    Debug.Log($"{participant.Account.DisplayName} Is Unmuted : (Muted For All : {participant.IsMutedForAll})");
}

[UserEvent(UserStatus.UserSpeaking)]
private void OnUserSpeaking(IParticipant participant)
{
    Debug.Log($"{participant.Account.DisplayName} Is Speaking : Audio Energy {participant.AudioEnergy}");
}

[UserEvent(UserStatus.UserNotSpeaking)]
private void OnUserNotSpeaking(IParticipant participant)
{
    Debug.Log($"{participant.Account.DisplayName} Is Not Speaking");
}

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.LocalUserMuted)]
private async void OnLocalUserMutedAsync()
{
    Debug.Log("Local User is Muted");
    await SavePlayerData();
}

[UserEventAsync(UserStatus.LocalUserUnmuted)]
private async void OnLocalUserUnmutedAsync()
{
    Debug.Log("Local User is Unmuted");
    await SavePlayerData();
}

[UserEventAsync(UserStatus.UserCrossMuted)]
private async void OnCrossMutedAsync(AccountId accountId)
{
    Debug.Log($"Player {accountId.DisplayName} has been Cross Muted");
    await SavePlayerData();
}

[UserEventAsync(UserStatus.UserCrossUnmuted)]
private async void OnCrossUnmutedAsync(AccountId accountId)
{
    Debug.Log($"Player {accountId.DisplayName} has been Cross Unmuted");
    await SavePlayerData();
}

[UserEventAsync(UserStatus.UserMuted)]
private async void OnUserMutedAsync(IParticipant participant)
{
    Debug.Log($"{participant.Account.DisplayName} Is Muted : (Muted For All : {participant.IsMutedForAll})");
    await SavePlayerData();
}

[UserEventAsync(UserStatus.UserUnmuted)]
private async void OnUserUnmutedAsync(IParticipant participant)
{
    Debug.Log($"{participant.Account.DisplayName} Is Unmuted : (Muted For All : {participant.IsMutedForAll})");
    await SavePlayerData();
}

[UserEventAsync(UserStatus.UserSpeaking)]
private async void OnUserSpeakingAsync(IParticipant participant)
{
    Debug.Log($"{participant.Account.DisplayName} Is Speaking : Audio Energy {participant.AudioEnergy}");
    await SavePlayerData();
}

[UserEventAsync(UserStatus.UserNotSpeaking)]
private async void OnUserNotSpeakingAsync(IParticipant participant)
{
    Debug.Log($"{participant.Account.DisplayName} Is Not Speaking");
    await SavePlayerData();
}

Last updated