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:
- Provide a plugin to handle the communication between C# and the browser.
- Register the DeepLink URL scheme.
- 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.
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 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 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.
- In Unity, open the
Assets\Scenes\SampleScene.unity
- Navigate to the
AgentAndPlugin
in the scene hierarchy - Update the
Greet Backend Cube
with your own greeting backend canister id - Update the
Greet Frontend
with your own greeting frontend - If you use a different URL scheme to launch your Unity project in ii_integration_dapp, please
- Update the
kAndroidScheme
&kAndroidHost
in AndroidPostBuildProcessor.cs accordingly. - Or update the
kURLScheme
&kURLIdentifier
in iOSPostBuildProcessor.cs accordingly.
- Update the
After updating your Unity project correctly, please build to the platform you want to build to in Unity, just
- Go to
File -> Build Settings
window - Switch to
Android
/iOS
platform - Click
Build
to build the app, or ClickBuild And Run
to build and run on the connected device.