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:
- Provide a plugin to handle the communication between C# and the browser.
- Register the App Links in the Android manifest file.
- Generate the
Ed25519KeyIdentity
in C# and pass the public key to the Web Brower. - Receive the
DelegationChain
from the Web Brower and composite theDelegationIdentity
from it. - 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 theDelegationIdentity
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 theClientGenerator
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.
- In Unity, open the
Assets\Scenes\SampleScene.unity
. - Navigate to the
AgentAndPlugin
in the scene hierarchy. - Update the
Greet Backend Canister
with your own greeting backend canister id. - Update the
Greet Frontend
with your own greeting frontend. - 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
- Go to
File -> Build Settings
window. - Switch to
iOS
platform. - Click
Build
to build to iOS platform.