Events
Events have been added to the ImmerseSession
and ImmerseReporting
classes to track user authentication and reporting initialization. This is particularly useful when using the auto authenticate feature.
To monitor user authentication, subscribe to the ImmerseSession.OnAuthenticate
event. This event returns a SessionData
object containing the host, token, any errors that occurred, and user information.
The example below shows how you can subscribe to the event, printing the authenticated user’s name on success or on a failure, the error that occurred:
using ImmerseSDK.Platform.Authentication;
ImmerseSession.OnAuthenticate += sessionData =>
{
if (sessionData.HasError)
{
Debug.LogError(sessionData.Error);
}
else
{
Debug.Log(sessionData.User.FullName);
}
};
Reporting statements cannot be sent until the user has authenticated and reporting has been initialized. This process all happens automatically when using the auto authenticate feature, but it is important not to try and send statements until it is complete. For this purpose, the ImmerseReporting.OnInitialize
event has been added.
The example below shows how you can subscribe to the event, printing an error if one should occur or “Reporting Initialized” on success.
using ImmerseSDK.Platform.Reporting;
ImmerseReporting.OnInitialize += result =>
{
if (result != ImmerseReporting.InitializationResult.Success)
{
Debug.LogError(result);
}
else
{
Debug.Log("Reporting initialized");
}
};
The PlatformEventTrigger
component provides an easy way to serialize events that trigger upon a platform event, such as authentication success.
When adding the script, it will not have any events listed. To add events, click the ‘Add New Event Type’ button at the bottom of the component.
Event | Description |
---|---|
AuthenticationSuccess | Platform authentication success |
AuthenticationFailure | Platform authentication failure |
ReportingReady | Ready to receive report statements (authentication was successful) |
ImmerseReady | Authentication was successful and in the case of a multiplayer app, the user is connected |