awaitAuthenticationService.Instance.SignInAnonymouslyAsync();// Don't sign out later, since that changes the anonymous token, which would prevent the player from exiting lobbies they're already in.
onSigninComplete?.Invoke();
try
{if(!AuthenticationService.Instance.IsSignedIn)
awaitAuthenticationService.Instance.SignInAnonymouslyAsync();// Don't sign out later, since that changes the anonymous token, which would prevent the player from exiting lobbies they're already in.
onSigninComplete?.Invoke();
}
catch
{UnityEngine.Debug.LogError("Failed to login. Did you remember to set your Project ID under Services > General Settings?");
throw;
}
// Note: If for some reason your login state gets weird, you can comment out the previous block and instead call AuthenticationService.Instance.SignOut().
// Then, running Play mode will fail to actually function and instead will log out of your previous anonymous account.
// When you revert that change and run Play mode again, you should be logged in as a new anonymous account with a new default name.
/// Anything which provides itself to a Locator can then be globally accessed. This should be a single access point for things that *want* to be singleton (that is,
/// when they want to be available for use by arbitrary, unknown clients) but might not always be available or might need alternate flavors for tests, logging, etc.
/// (See http://gameprogrammingpatterns.com/service-locator.html to learn more.)
#region Lobby API calls are rate limited, and some other operations might want an alert when the rate limits have passed.
// Note that some APIs limit to 1 call per N seconds, while others limit to M calls per N seconds. We'll treat all APIs as though they limited to 1 call per N seconds.
// Also, this is seralized, so don't reorder the values unless you know what that will affect.
/// Wrapper for all the interaction with the Relay API.
/// Relay acts as an intermediary between hosts and clients for privacy. Each player will connect to an obfuscated IP address provided by Relay as though connecting directly to other players.
/// </summary>
publicstaticclassRelayAPIInterface
{
/// <summary>
/// Only after an Allocation has been completed can a Relay join code be obtained. This code will be stored in the lobby's data as non-public
/// such that players can retrieve the Relay join code only after connecting to the lobby.
/// such that players can retrieve the Relay join code only after connecting to the lobby. (Note that this is not the same as the lobby code.)
if(id==m_localUser.ID||!m_localLobby.LobbyUsers.ContainsKey(id))// We don't hold onto messages, since an incoming user will be fully initialized before they send events.
if(id==m_localUser.ID||!m_localLobby.LobbyUsers.ContainsKey(id))// We don't need to hold onto messages if the ID is absent; users are initialized before they send events.
// The host disconnected, and Relay does not support host migration. So, all clients should disconnect.
}
/// <summary>
/// Relay uses raw pointers for efficiency. This converts them to byte arrays, assuming the stream contents are 1 byte for array length followed by contents.
/// UTP uses raw pointers for efficiency (i.e. C-style byte* instead of byte[]).
/// ReadMessageContents converts them back to byte arrays, assuming the stream contains 1 byte for array length followed by contents.
/// Any actual pointer manipulation and so forth happens service-side, so we simply need to convert back to a byte array here.
/// Responsible for setting up a connection with Relay using UTP, for the lobby host.
/// Responsible for setting up a connection with Relay using Unity Transport (UTP). A Relay Allocation is created by the host, and then all players
/// bind UTP to that Allocation in order to send data to each other.
/// Must be a MonoBehaviour since the binding process doesn't have asynchronous callback options.
/// </summary>
publicabstractclassRelayUtpSetup:MonoBehaviour
protectedabstractvoidJoinRelay();
/// <summary>
/// Shared behavior for binding to the Relay allocation, which is required for use.
/// Shared behavior for binding UTP to the Relay Allocation, which is required for use.
/// Note that a host will send bytes from the Allocation it creates, whereas a client will send bytes from the JoinAllocation it receives using a relay code.
if(m_joinState==(JoinState.Joined|JoinState.Bound)&&this!=null)// this will equal null (i.e. this component has been destroyed) if the host left the lobby during the Relay connection sequence.
if(joinAllocation==null||this==null)// The returned JoinAllocation is null if allocation failed. this would be destroyed already if you quit the lobby while Relay is connecting.
// In the future, remove FindVivoxId and pass the environment ID here instead.
m_vivoxId=null;
// SetID might be called after we've received the IChannelSession for remote players, which would mean after OnParticipantAdded. So, duplicate the VivoxID work here.
// SetID might be called after we've received the IChannelSession for remote players, which would mean after OnParticipantAdded. So, duplicate the VivoxID work here.
participant.SetIsMuteForAll(m_vivoxId,false,null);// Also note: This call is asynchronous, so it's possible to exit the lobby before this completes, resulting in a Vivox error.