Logging Into the Platform #

In this section, we’ll be logging in with the configured SDK. Note that this method of logging in is useful during development but is not appropriate for use in production.


Create the login script #

  1. Run make run to start Pragma Engine. Run this in a terminal with platform as the working directory.
  • Alternatively, Pragma Engine can be run from IntelliJ. From the IntelliJ toolbar in the upper right, ensure MainKt - LocalConfigured is selected, then click the play button.

  • Once the engine has successfully started it prints the message [main] INFO main - Pragma server startup complete.

  1. Create a Scripts folder in your Assetsfolder. Create a new C# script named PragmaManager.cs and open it.

  2. Paste the following code into the PragmaManager script.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pragma;
using Pragma.GameData;
using Pragma.Account;

public class PragmaManager : MonoBehaviour
{
    public PragmaSession session;
    // Start is called before the first frame update
    void Start()
    {
        session = new PragmaSession();

        SubscribeToEvents();
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void Login()
    {
        session.Account.LogIn(IdProvider.Unsafe, "test01", loginResult =>
        {
            if (loginResult.IsSuccessful)
            {
                // Success is handled in_session.Connection.OnInitiallyConnected above.
                // No reason you couldn't handle it here though.
                return;
            }
            else
            {
                // Something went wrong
            }
        });
    }

        private void SubscribeToEvents()
    {
        session.Connection.OnInitialized += OnPragmaInit;
        session.Connection.OnInitiallyConnected += OnPragmaInitiallyConnected;
        session.Connection.OnConnected += PlayerConnected;
        session.Connection.OnDegraded += OnPragmaDegraded;
        session.Connection.OnDisconnected += OnPragmaDisconnected;
    }

       private void UnsubscribeFromEvents()
    {
        session.Connection.OnInitialized -= OnPragmaInit;
        session.Connection.OnInitiallyConnected -= OnPragmaInitiallyConnected;
        session.Connection.OnConnected -= PlayerConnected;
        session.Connection.OnDegraded -= OnPragmaDegraded;
        session.Connection.OnDisconnected -= OnPragmaDisconnected;
    }

    private void OnPragmaInit()
    {
        Debug.Log("Pragma Initialized");
    }

    private void OnPragmaInitiallyConnected()
    {
        Debug.Log("You have successfully logged in");
        Debug.Log("LOG IN SUCCESS! id: " + session.Account.PragmaPlayerId);
    }

    private void PlayerConnected()
    {

    }

    private void OnPragmaDegraded(Connection.ConnectionError connectionError)
    {
        Debug.Log($"Connection Error: {connectionError.ToString()}");
    }

    private void OnPragmaDisconnected(Connection.ConnectionError connectionError)
    {
        Debug.Log($"Pragma Disconnected: {connectionError.ToString()}");
    }
}
Detailed view

In this code block:

  • Add all the connection state change lambdas in the Start() method.
  • Add a Login() method which we will hook up to a button later in this guide.
  1. Return to your Unity project. Right click in an empty part of the Hierarchy pane on the left side, click Create Empty, and name the GameObject PragmaManager.

  2. Drag the PragmaManager.cs script onto the PragmaManager GameObject.

  3. Right click in the Hierarchy pane and select UI then Button.

  4. Expand the Button object in the Hierarchy pane and select Text.

  5. In the Inspector pane, find the Text box with the default text of Button. Rename it by typing Login.

  6. In the Hierarchy pane, click on the Button object.

  7. In the On Click (), select the + sign, and drag PragmaManager from the Hierarchy pane onto None (Object) in the Inspector pane. Click No Function and select PragmaManager, then Login().

Log in #

  1. Click play, then click the Login button to connect to your locally running Pragma Engine instance.

  2. Navigate to Pragma Portal. Select Sign in with Pragma Unsafe and type in test04.

  3. Find the entry with the Player id for test01 from logging in via Unity.

  4. Return to your Unity project and scroll through the console messages until you find the “LOG IN SUCCESS!” message with a Player id.

  5. Compare the Player ids from steps 3 and 4, and confirm that they match.

All other Pragma Engine API calls from PragmaSession are available once logged in.