Unity
The Subroutine SDK for Unity can be integrated into your project in several ways. The simplest method is to import it using the Git URL via the Package Manager. In Unity, select Window -> Package Manager
In the top-left corner, hit plus sign and select "Add package from git URL..." and put in https://github.com/subroutinecom/unity-sdk
.
You can now start using the Subroutine SDK for Unity in your C# code. For the code snippet you'll need both the Game API token and the test user auth token from previous steps. In your code, you will need to create a Client object. To achieve this, create a new empty object in the current scene and attach a new script to it. Name the script SubroutineClient. In the script's implementation, you will instantiate the client:
using UnityEngine;
public class SubroutineClient : MonoBehaviour
{
public Subroutine.API.Client Client;
void Awake()
{
Client = new Subroutine.API.Client(
new SubroutineClient.API.ClientOptions
{
CoroutineRunner = this,
ApiToken = "<your game API token>",
TestUserAuthToken = "<test user auth token override>"
}
);
}
}
ApiToken
is the API token of your game that can be retrieved from your game's settings page.TestUserAuthToken
is an optional override that automatically authenticates the client with your test player. To obtain this token, you should follow the Creating Test Players guide.CoroutineRunner
is any MonoBehaviour. The SDK relies on running coroutines for data fetching and can be attached to any object.
With the API instantiated, you can now invoke a sample function to verify that everything is set up correctly. To do this, create an empty game object and attach a script to it. Then modify the Awake function as follows:
void Awake()
{
Client = new Subroutine.API.Client(
new SubroutineClient.API.ClientOptions
{
CoroutineRunner = this,
ApiToken = "<your game API token>",
TestUserAuthToken = "<test user auth token override>"
}
);
Client.Player.GetInventory(new Subroutine.API.PlayerAPI.GetInventoryProps { }, (response) =>
{
// This should be null
Debug.Log(response.Error);
// This will be 0, the user doesn't have anything yet.
Debug.Log(response.Holdings.Count);
});
}
Once you run your project, you shouldn't see any errors.
You're now ready to use the SDK and access all features provided by Subroutine. Be sure to explore the authentication section and establish a proper registration and authentication path for future implementation. Remember, you can always utilize the TestUserAuthToken override when testing the game with your personal test user.