Create Unity Project Files #

In this section, we’ll create the initial resources used in the rest of the Unity tutorials.

Prerequisites:

Create a MonoBehavior class #

  1. From your Unity project, use the Project pane to create a Scripts folder within the Assets folder.

  2. Right-click in the Scripts folder and create a new C# script named PragmaManager. When you create the script directly from Unity, the file is populated with a Unity MonoBehaviour class.

  3. Replace the code with the following:

    using Pragma;
    using UnityEngine;
    
    public class PragmaManager : MonoBehaviour
    {
        public Pragma.Player Player { get; private set; }
    
        private void Awake()
        {
            // The Pragma Runtime is automatically initialized on first retrieval.
            var runtime = Pragma.Runtime.Get();
    
            // This returns the first Player if available, or creates it. The Runtime is the source of truth for Player objects.
            Player = runtime.Player();
        }
    }
    

Method details #

  • Awake() is called when the GameObject is created.

  • Pragma.Runtime.Get() creates and initializes the Pragma Runtime, which is the main entrypoint into Pragma. In this case we use it to set configuration and access the Player session.

  • runtime.Player() is a convenience accessor to get (or create) the first Player session.

Create a PragmaManager GameObject #

  1. In your Unity editor, 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.

We’ll use this GameObject throughout the other Unity tutorials to link out PragmaManager.cs methods with various UI elements. For example: