Initialize Pragma Services #
In this section, we’ll initialize the various Pragma services that we’ll use in the other Unity tutorials.
Prerequisites:
- Set Up Unity Project
- Set Up the Unity SDK
- Create Unity Project Files
- Handle login and logout with Unity
Create an Initialize function #
Goal #
Initialize the Pragma Party, Game Instance, Friends, and Presence services from Unity.
The PartyApi
, GameInstanceApi
, FriendsApi
, and PresenceApi
Pragma SDKs for Unity provide Initialize()
methods for the various Pragma services. Use these methods to initialize the services in your PragmaManager
.
Steps #
In PragmaManager.cs
, add an InitializeServices()
method that uses the Initialize()
methods for each Pragma service:
public void InitializeServices()
{
Player.PartyApi.Initialize(result =>
{
if (result.IsFailure)
{
Debug.Log("Pragma -- Init failed");
}
else
{
Debug.Log("Pragma -- Party service initialized");
}
});
}
Initialize upon login #
Goal #
Initialize all services when a user logs in.
Steps #
In the PragmaManager.cs
HandleLoggedIn()
method, add a call to InitializeServices()
if login is successful:
private void HandleLoggedIn(Pragma.Result result)
{
if (result.IsFailure)
{
Debug.LogErrorFormat("Pragma -- Login failed: {0}", result.ErrorCode);
return;
}
else
{
PragmaId myPragmaId = Player.Account.PragmaPlayerId;
string myPragmaIdString = myPragmaId.ToString();
Debug.Log("Pragma -- Logged in. Pragma ID: " + myPragmaIdString);
InitializeServices();
}
}