Skip to content

Instantly share code, notes, and snippets.

@tnj
Created December 3, 2012 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tnj/4193280 to your computer and use it in GitHub Desktop.
Save tnj/4193280 to your computer and use it in GitHub Desktop.
DeployGate with Unity

Preparation

Code (C#)

On your app startup, install DeployGate into your process:

// Get Android context
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject app = activity.Call<AndroidJavaObject>("getApplicationContext");

// Install DeployGate, make sure it will not called twice in your app
AndroidJavaClass dg = new AndroidJavaClass("com.deploygate.sdk.DeployGate");
dg.CallStatic("install", app);
// OR if you want bit more secure (with provider account name) try below:
// dg.CallStatic("install", app, "YOUR_DEPLOYGATE_USERNAME");

DeployGate#install() work asynchronously. May need some time to initialize, within a second in most case.

After that, at the point of check authority, write the code like this:

// Check the app is authorized (this will block until finish the initialization above)
bool isAuthorized = dg.CallStatic<bool>("isAuthorized");
if (!isAuthorized) {
  // quit the app
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment