Skip to main content

Unity sample

This sample demonstrates one way to integrate Identity Integration with Unity on mobile platforms. If you never play with Unity Android/iOS, please read Getting started with Android and Gettting Started with iOS.

Overview

In this example, you can learn how to communicate with the BIG from C#. As we described in Internet Identity Integration, the game mainly focuses on:

  1. Provide a plugin to handle the communication between C# and the browser.
  2. Register the DeepLink URL scheme.
  3. Generate the Ed25519KeyIdentity in C# and pass the public key to the Web Brower.
  4. Receive the DelegationChain from the Web Brower and composite the DelegationIdentity from it.
  5. Use the DelegationIdentity to communicate with the backend canister.

Key Files

There're several important files in this example.

  • AndroidPostBuildProcessor.cs
    This is a Unity post-build processor for Android platform, which inserts the DeepLink URL scheme into the AndroidManifest.xml.

  • iOSPostBuildProcessor.cs
    This is a Unity post-build processor for iOS platform, which inserts the DeepLink URL scheme into the pList file.

  • DeepLinkPlugin.cs
    It's a plugin which provides functions to open the web browser, handle the DeepLink activation, and composite the DelegationIdentity from Json string.

  • GreetingClient.cs
    This provides the C# APIs for calling the Greeting backend canister in ii_integration_dapp. It can be generated by running the ClientGenerator provided by BIG.NET.

  • TestICPAgent.cs
    This is a testing script which calls the APIs provided by GreetingClient.cs to communicate with the greeting backend canister.

Deployment

The current Unity project is configured to use the deployed dapp. If you deploy your own dapp by following ii_integration_dapp, you need to make some modifications before you start to build this project to mobile platforms in Unity.

  1. In Unity, open the Assets\Scenes\SampleScene.unity
  2. Navigate to the AgentAndPlugin in the scene hierarchy
  3. Update the Greet Backend Cube with your own greeting backend canister id
  4. Update the Greet Frontend with your own greeting frontend
  5. If you use a different URL scheme to launch your Unity project in ii_integration_dapp, please

After updating your Unity project correctly, please build to the platform you want to build to in Unity, just

  1. Go to File -> Build Settings window
  2. Switch to Android / iOS platform
  3. Click Build to build the app, or Click Build And Run to build and run on the connected device.