Event Examples

Events - Action/Delegates

Synchronous - Normal way of doing events

using System;
using UnityEngine;
using VivoxUnity;

public class NormalEvents : MonoBehaviour
{
    public event Action<ILoginSession> LoggingIn;

    void Start()
    {
        LoggingIn += PlayerLoggingIn;
    }
    private void OnApplicationQuit()
    {
        LoggingIn -= PlayerLoggingIn;
    }

    public void PlayerLoggingIn(ILoginSession loginSession)
    {
        Debug.Log($"Invoking Normal Event from {nameof(PlayerLoggingIn)}");
    }
}

Synchronous - Easy Code way of doing events

Read more about [Inject] attribute and Method Injection here

Easy Code Dynamic Events

Don't want to Subscribe and Unsubscribe from events or use Zenject dependency injection. Use Dynamic events instead. They are a tad bit slower in some cases but events are fire and forget and aren't called in Unity's Update() loop, so you really can't tell the difference until you have hundreds of game objects firing events.

Vivox events arent fired that often so unless you are updating hundreds of gameobejcts based on a players's name or login status you should be fine to use Dynamic Events.

Synchronous - Dynamic Events

Asynchronous - Dynamic Async Events

Last updated

Was this helpful?