EasyManager.cs

EasyManager inherits from MonoBehaviour so it can be attached to a GameObject and inherited to make your own Custom VivoxManager. EasyManager is basically a super class/wrapper for all EasyCode functionality. Instead of using EasyManager you can access EasyCode functionality directly/separately by injecting necessary classes in your script by using the [Inject] attribute. Read more about it here

Necessary libraries for EasyManager.cs to work. namespace separate's your project or script from other peoples scripts or libraries that use similar names to avoid compile errors. It also forces people to use a using statement when they want to use your script or library

using EasyCodeForVivox.Events;
using EasyCodeForVivox.Utilities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using VivoxUnity;
using Zenject;

namespace EasyCodeForVivox
{

Private variables that are set by the Initialize() method.

    private EasyLogin _login;
    private EasyChannel _channel;
    private EasyAudioChannel _voiceChannel;
    private EasyTextChannel _textChannel;
    private EasyUsers _users;
    private EasyMessages _messages;
    private EasyMute _mute;
    private EasyTextToSpeech _textToSpeech;
    private EasyAudio _audio;
    private EasySettingsSO _settings;
    private EasyEvents _events;

Intialize() method is used to Inject and assign the private variables to any classes EasyManager needs to function. Instances are injected by Zenject dependency injection by using the [Inject] attribute

    [Inject]
    public void Initialize(EasyLogin login, EasyChannel channel, EasyAudioChannel voiceChannel, EasyTextChannel textChannel,
        EasyUsers users, EasyMessages messages, EasyMute mute, EasyTextToSpeech textToSpeech, EasyAudio audio,
        EasySettingsSO settings, EasyEvents events)
    {
        _login = login ?? throw new ArgumentNullException(nameof(login));
        _channel = channel ?? throw new ArgumentNullException(nameof(channel));
        _voiceChannel = voiceChannel ?? throw new ArgumentNullException(nameof(voiceChannel));
        _textChannel = textChannel ?? throw new ArgumentNullException(nameof(textChannel));
        _users = users ?? throw new ArgumentNullException(nameof(users));
        _messages = messages ?? throw new ArgumentNullException(nameof(messages));
        _mute = mute ?? throw new ArgumentNullException(nameof(mute));
        _textToSpeech = textToSpeech ?? throw new ArgumentNullException(nameof(textToSpeech));
        _audio = audio ?? throw new ArgumentNullException(nameof(audio));
        _settings = settings ?? throw new ArgumentNullException(nameof(settings));
        _events = events ?? throw new ArgumentNullException(nameof(events));
    }

I have tried to break up bigger methods and explain them in better detail. By clicking the tabs or exapandles you will see more info reated to what each method is doing

InitializeClient() is used to initialize Vivox Client, register Dynamic Events, and subscribe to necessary events for EasyCode to work.

A Pre-Processor Directive is used to disable logging for builds for faster performance. Read more about it here

// disable Debug.Log Statements in the build for better performance
#if UNITY_EDITOR Debug.unityLogger.logEnabled = true; 
#else Debug.unityLogger.logEnabled = false; 
#endif

UnitializeClient() is used to clean up resources used by Vivox and EasyCode. Also used to subscribe from events to prevent memory leaks

    public void UnitializeClient()
    {
        _audio.Unsubscribe(EasySession.Client);
        UnsubscribeToVivoxEvents();
        EasySession.Client.Uninitialize();
    }

Subscribe To Vivox Events

SubscribeToVivoxEvents(); Subscribes to relevant Vivox events .

public void SubscribeToVivoxEvents()

Audio Device Events

EasySession.Client.AudioInputDevices.AvailableDevices.AfterKeyAdded += _audio.OnAudioInputDeviceAdded;
EasySession.Client.AudioInputDevices.AvailableDevices.BeforeKeyRemoved += _audio.OnAudioInputDeviceRemoved;
EasySession.Client.AudioInputDevices.AvailableDevices.AfterValueUpdated += _audio.OnAudioInputDeviceUpdated;

EasySession.Client.AudioOutputDevices.AvailableDevices.AfterKeyAdded += _audio.OnAudioOutputDeviceAdded;
EasySession.Client.AudioOutputDevices.AvailableDevices.BeforeKeyRemoved += _audio.OnAudioOutputDeviceRemoved;
EasySession.Client.AudioOutputDevices.AvailableDevices.AfterValueUpdated += _audio.OnAudioOutputDeviceUpdated;

Use EasySession.cs to access VivoxClient (Client) and its Audio Device events

Login Events

 // Subscribe to Login Related Events
 _events.LoggingIn += OnLoggingIn;
 _events.LoggedIn += OnLoggedIn;
 _events.LoggedIn += OnLoggedInSetup;
 _events.LoggingOut += OnLoggingOut;
 _events.LoggedOut += OnLoggedOut;
 
 _events.LoginAdded += OnLoginAdded;
 _events.LoginRemoved += OnLoginRemoved;
 _events.LoginUpdated += OnLoginUpdated;

Uses EasyEvents.cs to access Login events

You can also access EasyEvents by injecting it into your class using Zenject dependency injection. Read more about it here.

Channel Events

 // Subscribe to Channel Related Events
_events.ChannelConnecting += OnChannelConnecting;
_events.ChannelConnected += OnChannelConnected;
_events.ChannelDisconnecting += OnChannelDisconnecting;
_events.ChannelDisconnected += OnChannelDisconnected;

Uses EasyEvents.cs to access Channel events

You can also access EasyEvents by injecting it into your class using Zenject dependency injection. Read more about it here.

Audio Channel Events

 // Subscribe to Channel Related Events
_events.AudioChannelConnecting += OnVoiceConnecting;
_events.AudioChannelConnected += OnVoiceConnected;
_events.AudioChannelDisconnecting += OnVoiceDisconnecting;
_events.AudioChannelDisconnected += OnVoiceDisconnected;

Uses EasyEvents.cs to access Audio Channel events

You can also access EasyEvents by injecting it into your class using Zenject dependency injection. Read more about it here.

Text Channel Events

 // Subscribe to Channel Related Events
 _events.TextChannelConnecting += OnTextChannelConnecting;
 _events.TextChannelConnected += OnTextChannelConnected;
 _events.TextChannelDisconnecting += OnTextChannelDisconnecting;
 _events.TextChannelDisconnected += OnTextChannelDisconnected;

Uses EasyEvents.cs to access Text Channel events

You can also access EasyEvents by injecting it into your class using Zenject dependency injection. Read more about it here.

Message Events

 // Subscribe to Channel Message Related Events
_events.ChannelMessageRecieved += OnChannelMessageRecieved;
_events.EventMessageRecieved += OnEventMessageRecieved;

 // Subscribe to Direct Message Related Events
 _events.DirectMessageRecieved += OnDirectMessageRecieved;
 _events.DirectMessageFailed += OnDirectMessageFailed;

Uses EasyEvents.cs to access Channel and Direct message events

You can also access EasyEvents by injecting it into your class using Zenject dependency injection. Read more about it here.

User Events

The keywords Fire and Called are used interchangeably

_events.UserJoinedChannel += OnUserJoinedChannel;
_events.UserLeftChannel += OnUserLeftChannel;
_events.UserValuesUpdated += OnUserValuesUpdated;

Uses EasyEvents.cs to access User events

You can also access EasyEvents by injecting it into your class using Zenject dependency injection. Read more about it here.

_events.UserMuted += OnUserMuted;
_events.UserUnmuted += OnUserUnmuted;
_events.UserSpeaking += OnUserSpeaking;
_events.UserNotSpeaking += OnUserNotSpeaking;

Uses EasyEvents.cs to access User events

You can also access EasyEvents by injecting it into your class using Zenject dependency injection. Read more about it here.

Text To Speech ( TTS ) Events

 // Subscribe to Text-To-Speech related events
 _events.TTSMessageAdded += OnTTSMessageAdded;
 _events.TTSMessageRemoved += OnTTSMessageRemoved;
 _events.TTSMessageUpdated += OnTTSMessageUpdated;

Uses EasyEvents.cs to access Text-To-Speech events

You can also access EasyEvents by injecting it into your class using Zenject dependency injection. Read more about it here.

Unsubscribe From Vivox Events

UnsubscribeToVivoxEvents() unsubscribes from all the events explained above. Refer to explanations above for each category. This is called on OnApplicationQuit() in Unity

Last updated