Skip to main content

Unity Android sample

This sample demonstrates one way to integrate Identity Integration with Unity on iOS. If you never play with Unity iOS, please read Getting started with iOS document.

Overview

In this example, you can learn how to communicate with the IC 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 App Links in the Android manifest file.
  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.

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

  • DeepLinkPlugin.cs
    It's a plugin which provides functions to open the web browser, handle the Universal Links 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 ICP.NET.

  • TestICPAgent.cs
    This is a testing script which can parse the delegation identity and call 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. And the apple-app-site-association file contains personal team id and app bundle id. 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 iOS platform 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 Canister with your own greeting backend canister id.
  4. Update the Greet Frontend with your own greeting frontend.
  5. Please update the kURLIdentifier in iOSPostBuildProcessor.cs to the URL of your deployed universallink_website.

After updating your Unity project correctly, please build to iOS platform in Unity, just

  1. Go to File -> Build Settings window.
  2. Switch to iOS platform.
  3. Click Build to build to iOS platform.