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 editor, but in non-simul mode in a normal build. The SDK initializes and checks whether the player can start the game. If the game starts successfully, an achievement is unlocked.
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
public class IndiePassDRM : MonoBehaviour
{
private readonly string gameUuid = "YOUR_GAME_UUID";
private readonly string publicKey = "YOUR_PUBLIC_KEY";
private async void Awake()
{
#if UNITY_EDITOR
IndiePassSDK.setSimul(true);
bool autoclose = false; // Disable autoclose during development
#else
IndiePassSDK.setSimul(false);
bool autoclose = true; // Enable autoclose in production
#endif
try
{
bool isValid = IndiePassSDK.initSdk(gameUuid, publicKey, autoclose);
if (isValid)
{
IndiePassSDK.unlockAchievement("YOUR_ACHIEVEMENT_KEY");
SceneManager.LoadScene("myScene", LoadSceneMode.Single);
}
else
{
Debug.LogError("SDK initialization failed");
if (!autoclose)
{
Application.Quit();
}
}
}
catch (Exception e)
{
Debug.LogError("Error initializing SDK: " + e.Message);
if (!autoclose)
{
Application.Quit();
}
}
}
}
Key Changes in v0.0.3
initSdkreplacesverifyCertificate: The new method provides initialization and validation in one call- UUID format: Game ID is now a string UUID instead of an integer
- autoclose parameter: New parameter to control automatic game closure on validation failure
- Set to
falseduring development to prevent unexpected closures - Set to
truein production for proper DRM enforcement
- Set to
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 objectcontaining the script - A camera with at least a plain background.
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.