Skip to content

Instantly share code, notes, and snippets.

@FullStackIndie
Created November 22, 2022 06:49
Show Gist options
  • Save FullStackIndie/fa5981492c7199b492f5524413483cf2 to your computer and use it in GitHub Desktop.
Save FullStackIndie/fa5981492c7199b492f5524413483cf2 to your computer and use it in GitHub Desktop.
VivoxVoiceManager
using Unity.Services.Authentication;
using UnityEngine;
public class VivoxManager : MonoBehaviour
{
private VivoxVoiceManager _vivoxManager;
private void Awake()
{
_vivoxManager = VivoxVoiceManager.Instance;
}
private void Start()
{
SubscribeToLoginEvents();
}
private void OnApplicationQuit()
{
UnsubscribeToLoginEvents();
}
private void SubscribeToLoginEvents()
{
_vivoxManager.OnUserLoggedInEvent += OnPlayerLoggedIn;
_vivoxManager.OnUserLoggedInEvent += OnPlayerLoggedIn;
}
private void UnsubscribeToLoginEvents()
{
_vivoxManager.OnUserLoggedInEvent -= OnPlayerLoggedIn;
_vivoxManager.OnUserLoggedInEvent -= OnPlayerLoggedIn;
}
public void Login()
{
_vivoxManager.Login("murph");
}
private void OnPlayerLoggedIn()
{
Debug.Log($"Player {_vivoxManager.LoginSession.LoginSessionId.DisplayName} has Successfully Logged In");
}
private void OnPlayerLoggedOut()
{
Debug.Log($"Player {_vivoxManager.LoginSession.LoginSessionId.DisplayName} has been Logged Out");
}
private void DisplayPlayerIds()
{
// Unity's Authentication service - if you are using
Debug.Log($"{AuthenticationService.Instance.PlayerId}");
// Login Session
Debug.Log($"{_vivoxManager.LoginSession.LoginSessionId.Name}");
Debug.Log($"{_vivoxManager.LoginSession.LoginSessionId.DisplayName}");
}
private void CheckIfPlayerIsLoggedIn()
{
if(_vivoxManager.LoginState == VivoxUnity.LoginState.LoggedIn)
{
// your code here
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment