Login 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 Login Events in EasyCode

EasyManager

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

// Login Event Callbacks

protected override void OnLoggingIn(ILoginSession loginSession)
{
    base.OnLoggingIn(loginSession);
}

protected override void OnLoggedIn(ILoginSession loginSession)
{
    base.OnLoggedIn(loginSession);
}

protected override void OnLoggingOut(ILoginSession loginSession)
{
    base.OnLoggingOut(loginSession);
}

protected override void OnLoggedOut(ILoginSession loginSession)
{
    base.OnLoggedOut(loginSession);
}

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

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

protected override void OnLoginUpdated(ILoginSession loginSession)
{
    base.OnLoginUpdated(loginSession);
}

EasyEvents

public void SubscribeToLoginEvents()
{
    _events.LoggingIn += OnLoggingIn;
    _events.LoggedIn += OnLoggedIn;
    _events.LoggingOut += OnLoggingOut;
    _events.LoggedOut += OnLoggedOut;

    _events.LoginAdded += OnLoginAdded;
    _events.LoginRemoved += OnLoginRemoved;
    _events.LoginUpdated += OnLoginUpdated;
}

public void UnsubscribeToLoginEvents()
{
    _events.LoggingIn -= OnLoggingIn;
    _events.LoggedIn -= OnLoggedIn;
    _events.LoggingOut -= OnLoggingOut;
    _events.LoggedOut -= OnLoggedOut;

    _events.LoginAdded -= OnLoginAdded;
    _events.LoginRemoved -= OnLoginRemoved;
    _events.LoginUpdated -= OnLoginUpdated;
}


#region Login / Logout Callbacks

protected virtual void OnLoggingIn(ILoginSession loginSession)
{
        Debug.Log($"Logging In : {loginSession.LoginSessionId.DisplayName}");
}

protected virtual void OnLoggedIn(ILoginSession loginSession)
{
    Debug.Log($"Logged in : {loginSession.LoginSessionId.DisplayName}  : Presence = {loginSession.Presence.Status}");
}

protected virtual void OnLoggingOut(ILoginSession loginSession)
{
        Debug.Log($"Logging out : {loginSession.LoginSessionId.DisplayName}  : Presence = {loginSession.Presence.Status}");
}

protected virtual void OnLoggedOut(ILoginSession loginSession)
{
        Debug.Log($"Logged out : {loginSession.LoginSessionId.DisplayName}  : Presence = {loginSession.Presence.Status}");
}

protected virtual void OnLoginAdded(AccountId accountId)
{
        Debug.Log($"LoginSession Added : For user {accountId.Name}");
}

protected virtual void OnLoginRemoved(AccountId accountId)
{
        Debug.Log($"Login Removed : For user {accountId}");
}

protected virtual void OnLoginUpdated(ILoginSession loginSession)
{
        Debug.Log($"LoginSession has been Updated : {loginSession.LoginSessionId.DisplayName} : Presence = {loginSession.Presence.Status}");
}

#endregion

Dynamic Events

Make sure the parameter in your method matches the event type. See what parameter is required for each Login 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 +=/-=

[LoginEvent(LoginStatus.LoggingIn)]
private void OnPlayerLoggingIn(ILoginSession loginSession)
{
    Debug.Log($"Logging In : {loginSession.LoginSessionId.DisplayName}");
}

[LoginEvent(LoginStatus.LoggedIn)]
private void OnPlayerLoggedIn(ILoginSession loginSession)
{
    Debug.Log($"Logged in : {loginSession.LoginSessionId.DisplayName}  : Presence = {loginSession.Presence.Status}");
}

[LoginEvent(LoginStatus.LoggingOut)]
private void OnPlayerLoggingOut(ILoginSession loginSession)
{
    Debug.Log($"Logging out : {loginSession.LoginSessionId.DisplayName}  : Presence = {loginSession.Presence.Status}");
}

[LoginEvent(LoginStatus.LoggedOut)]
private void OnPlayerLoggedOut(ILoginSession loginSession)
{
    Debug.Log($"Logged out : {loginSession.LoginSessionId.DisplayName}  : Presence = {loginSession.Presence.Status}");
}

[LoginEvent(LoginStatus.LoginAdded)]
private void OnLoginSessionAdded(AccountId accountId)
{
    Debug.Log($"A new Login was added for player {accountId.DisplayName}");
}

[LoginEvent(LoginStatus.LoginRemoved)]
private void OnLoginSessionRemoved(AccountId accountId)
{
    Debug.Log($"A new Login was removed for player {accountId.DisplayName}");
}

[LoginEvent(LoginStatus.LoginValuesUpdated)]
private void OnLoginSessionValuesUpdated(ILoginSession loginSession)
{
    Debug.Log($"LoginSession has been updated for player {loginSession.LoginSessionId.DisplayName}");
}

Dynamic Async Events

Make sure the parameter in your method matches the event type. See what parameter is required for each Login 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

[LoginEventAsync(LoginStatus.LoggingIn)]
private async void OnPlayerLoggingInAsync(ILoginSession loginSession)
{
    Debug.Log($"Logging In : {loginSession.LoginSessionId.DisplayName}");
    await GetJoinedLobbies();
}

[LoginEventAsync(LoginStatus.LoggedIn)]
private async void OnPlayerLoggedInAsync(ILoginSession loginSession)
{
    Debug.Log($"Logged in : {loginSession.LoginSessionId.DisplayName}  : Presence = {loginSession.Presence.Status}");
    await LoadPlayerData();
}

[LoginEventAsync(LoginStatus.LoggingOut)]
private async void OnPlayerLoggingOutAsync(ILoginSession loginSession)
{
    Debug.Log($"Logging out : {loginSession.LoginSessionId.DisplayName}  : Presence = {loginSession.Presence.Status}");
    await RemovePlayerFromLobby();
}

[LoginEventAsync(LoginStatus.LoggedOut)]
private async void OnPlayerLoggedOutAsync(ILoginSession loginSession)
{
    Debug.Log($"Logged out : {loginSession.LoginSessionId.DisplayName}  : Presence = {loginSession.Presence.Status}");
    await SavePlayerData();
}

[LoginEventAsync(LoginStatus.LoginAdded)]
private async void OnLoginSessionAddedAsync(AccountId accountId)
{
    Debug.Log($"A new Login was added for player {accountId.DisplayName}");
    await GetJoinedLobbies();
}

[LoginEventAsync(LoginStatus.LoginRemoved)]
private async void OnLoginSessionRemovedAsync(AccountId accountId)
{
    Debug.Log($"A new Login was removed for player {accountId.DisplayName}");
    await RemovePlayerFromLobby();
}

[LoginEventAsync(LoginStatus.LoginValuesUpdated)]
private async void OnLoginSessionValuesUpdatedAsync(ILoginSession loginSession)
{
    Debug.Log($"LoginSession has been updated for player {loginSession.LoginSessionId.DisplayName}");
    await UpdatePlayerData();
}

Last updated