Initialize Pragma Services #

In this section, we’ll initialize the Party and Game Instance APIs that we’ll use in the other Unity tutorials.

Prerequisites:

Create an Initialize function #

Goal #

Initialize the Pragma Party API and Game Instance API for Unity.

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");
        }
    });

    Player.GameInstanceApi.Initialize(result =>
    {
        if (result.IsFailure)
        {
            Debug.Log("Pragma -- Game instance API initialization failed");
        }
        else 
        {
            Debug.Log("Pragma -- Game instance API 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();
    }
}