Skip to main content

Unity Integration

Script IndiePass

Here's an example of how to use the SDK in Unity:

In this example, we start the game in simul mode in the client, but in non-simul mode in a normal build. Check whether the player can start the game. If the game starts, an achievement is unlocked.

assets/scripts/IndiePassDRM.cs
using System;
using UnityEngine;
using UnityEngine.SceneManagement;

public class IndiePassDRM : MonoBehaviour
{
private readonly string publicKey = "YOUR_PUBLIC_KEY";
private async void Awake()
{

#if UNITY_EDITOR
IndiePassSDK.setSimul(true);
#else
IndiePassSDK.setSimul(false);
#endif
try
{
bool isValid = IndiePassSDK.verifyCertificate(YOUR_GAME_ID, publicKey);
if (isValid)
{
IndiePassSDK.unlockAchievement("YOUR_ACHIEVEMENT_KEY");
SceneManager.LoadScene("myScene", LoadSceneMode.Single);
}
else
{
Debug.LogError("Error verifying certificate ");
Application.Quit();
}

}
catch (Exception e)
{
Debug.LogError("Error verifying certificate: " + e.Message);
Application.Quit();
}
}
}

Boot scene configuration example

Here we'll make sure that this script is called as soon as possible. We'll show you the procedure for users of the free version, the difference with other Unity licenses being that we can't execute this code before the splash art.

Step 1 - Create a starter scene

Create your scene, which will consist of:

  • A game object containing the script
  • A camera with at least a plain background.
tip

If you've got splash art to display, this is the place to display it!

Step 2 - Put the script at the top of the execution stack

To avoid any code execution before the script IndiePass.cs, we're going to place the script in the right place in the execution stack. Go to Edit -> Project Settings -> Script Execution Order and set your DRM script as high as possible (the lowest value).

Step 3 - Add your starter scene to the build

Once your scene is ready, congratulations, all you have to do is add it to Build Settings, making sure to set it to the very top (position 0). Uncheck it for builds not destined for IndiePass. You're ready to test your game.