Skip to main content
BETA
HomeIntegration BuilderAPI ReferenceGuides
View Mirror World on Github
Join the Discord server

Language:

Unity Integration Guide

This guide will walk you through the setup process for the Mirror World Smart SDK on Unity.

1. Create a Developer Account

Create a developer account on the Developer dashboard. Create project and create an API Key. If you already have an API Key, you may skip this step and proceed to the next one.

2. Import the Mirror World SDK

There are 2 ways to install the Mirror World Unity SDK:

  1. One way is to download the latest release assets from the official GitHub repository. Import it to your project Assets > Import Package > Custom Package and select the package you just downloaded.

  2. You may also search for the package in the Unity Assets Store with the keyword "com.mirror.sdk" and import it.

3. Configuration

Manual configuration with prefab

image

Explanation of the fields above image:

  • Api Key: Input your API key from the developer dashboard.
  • Debug Mode: If you check this, you will be able to see all the console output and error notices on the console.
  • Environment: Choose the environment you want to use.
  • Debug Email and Password: In the pre-release beta, you can only login to the SDK using this function.

Dynamic Configuration

If you don't want to add a game object to your scene,you can init Mirror World SDK with the following code:

DynamicConfiguration
Copy

GameObject mirrorObj = new GameObject("MirrorSDK", typeof(MirrorSDK));
string apiKey = "your api key";
bool debugMode = true;
Environment environment = Environment.StagingDevnet;
MirrorSDK.InitSDK(apiKey, mirrorObj, debugMode, environment);

4. Usage

After configuring the SDK, if you want to call some API of SDK in your app, you should lead users to login first.

Call up login page

DynamicConfiguration
LoginActivity.cs
Copy

MirrorSDK.StartLogin();

And if you want to do something after the logging is successful,you can pass an action to it as follows code:

LoginWithCallback.cs
Copy

MirrorSDK.StartLogin((isSuccess) => {
if(isSuccess){
Debug.Log("Login success!");
} else{
Debug.Log("Login failed!");
}
});

Packaging Your Application

After development, you need to do some configuration if you want to package your app for distribution.

Packaging for Android

Switch to Android platform Find File -> Build and settings -> Choose Android platform (If you are not) -> Click switch platform button.`

Edit AndroidManifest.xml Find: File → Build and settings → Player Settings → Publishing Settings → Build → Custom Main Manifest

Check it, and you may see the path of this file. Let's edit it to add permissions for internet

DynamicConfiguration
LoginActivity.cs
AndroidManifest.xml
Copy

<uses-permission android:name="android.permission.INTERNET" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"/>
</intent>
</queries>

Register this activity

Register Activity

DynamicConfiguration
LoginActivity.cs
AndroidManifest.xml
Copy

<activity
android:name="com.mirror.sdk.activities.RedirectActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="mwsdk"/>
</intent-filter>
</activity>

Finally your AndroidManifest.xml file should look like this:

DynamicConfiguration
LoginActivity.cs
AndroidManifest.xml
Copy

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mirror.mirrorworld_sdk_android">
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"/>
</intent>
</queries>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Mirrorworldsdkandroid"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.mirror.sdk.activities.RedirectActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="mwsdk"/>
</intent-filter>
</activity>
</application>
</manifest>

Configure launcherTemplate.gradle

Use the same function to open your launcherTemplate.gradle file. Add this to dependencies:

So the final dependencies may like this:

DynamicConfiguration
LoginActivity.cs
AndroidManifest.xml
launcherTemplate.gradle
Copy

apply plugin: 'com.android.application'
dependencies {
implementation project(':unityLibrary')
implementation 'androidx.browser:browser:1.3.0'
}

Configure gradleTemplate.properties

Add these lines to the end of the file:

DynamicConfiguration
LoginActivity.cs
AndroidManifest.xml
launcherTemplate.gradle
gradleTemplate.properties
Copy

android.useAndroidX=true
android.enableJetifier=true

For more information, you can refer to the official Android documentation.

Packaging For iOS

Build your XCode project

Find File → Build and settings → iOS → Switch Platform → Build

Add Mirror World Framework

Open the build XCode project.

Select your project root → TARGETS / Unity-iPhone → Build pharses → Copy Files Change the destination to "Frameworks" and click "+" button to add MirrorWorldSDK.framework to your project.

Edit UnityAppController.mm

First, add this import to head of the file:

DynamicConfiguration
LoginActivity.cs
AndroidManifest.xml
launcherTemplate.gradle
gradleTemplate.properties
UnityAppController.cs
Copy

// Import statement at head of file
#import <MirrorWorldSDK/MirrorWorldSDK-Swift.h>
// Then add this to the openUrl function
[[MirrorWorldSDK share] handleOpenWithUrl:url];

So, finally your openUrl function should look like this:

DynamicConfiguration
LoginActivity.cs
AndroidManifest.xml
launcherTemplate.gradle
gradleTemplate.properties
UnityAppController.cs
Copy

- (BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary<NSString*, id>*)options
{
id sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey], annotation = options[UIApplicationOpenURLOptionsAnnotationKey];
NSMutableDictionary<NSString*, id>* notifData = [NSMutableDictionary dictionaryWithCapacity: 3];
if (url)
{
notifData[@"url"] = url;
UnitySetAbsoluteURL(url.absoluteString.UTF8String);
}
if (sourceApplication) notifData[@"sourceApplication"] = sourceApplication;
if (annotation) notifData[@"annotation"] = annotation;
AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);
[[MirrorWorldSDK share] handleOpenWithUrl:url];
return YES;
}

Going Further

Great! At this point you're pretty much ready to start doing building with the Unity SDK for Mirror World. There are a few things you can do to proceed from here:

Getting Support

If you're stuck or just looking for support, you may also schedule a support call with our team.

Unity Integration Guide

This guide will walk you through the setup process for the Mirror World Smart SDK on Unity.

1. Create a Developer Account

Create a developer account on the Developer dashboard. Create project and create an API Key. If you already have an API Key, you may skip this step and proceed to the next one.

2. Import the Mirror World SDK

There are 2 ways to install the Mirror World Unity SDK:

  1. One way is to download the latest release assets from the official GitHub repository. Import it to your project Assets > Import Package > Custom Package and select the package you just downloaded.

  2. You may also search for the package in the Unity Assets Store with the keyword "com.mirror.sdk" and import it.

3. Configuration

Manual configuration with prefab

image

Explanation of the fields above image:

  • Api Key: Input your API key from the developer dashboard.
  • Debug Mode: If you check this, you will be able to see all the console output and error notices on the console.
  • Environment: Choose the environment you want to use.
  • Debug Email and Password: In the pre-release beta, you can only login to the SDK using this function.

Dynamic Configuration

If you don't want to add a game object to your scene,you can init Mirror World SDK with the following code:

4. Usage

After configuring the SDK, if you want to call some API of SDK in your app, you should lead users to login first.

Call up login page

And if you want to do something after the logging is successful,you can pass an action to it as follows code:

LoginWithCallback.cs
Copy

MirrorSDK.StartLogin((isSuccess) => {
if(isSuccess){
Debug.Log("Login success!");
} else{
Debug.Log("Login failed!");
}
});

Packaging Your Application

After development, you need to do some configuration if you want to package your app for distribution.

Packaging for Android

Switch to Android platform Find File -> Build and settings -> Choose Android platform (If you are not) -> Click switch platform button.`

Edit AndroidManifest.xml Find: File → Build and settings → Player Settings → Publishing Settings → Build → Custom Main Manifest

Check it, and you may see the path of this file. Let's edit it to add permissions for internet

Register this activity

Register Activity

Finally your AndroidManifest.xml file should look like this:

Configure launcherTemplate.gradle

Use the same function to open your launcherTemplate.gradle file. Add this to dependencies:

So the final dependencies may like this:

Configure gradleTemplate.properties

Add these lines to the end of the file:

For more information, you can refer to the official Android documentation.

Packaging For iOS

Build your XCode project

Find File → Build and settings → iOS → Switch Platform → Build

Add Mirror World Framework

Open the build XCode project.

Select your project root → TARGETS / Unity-iPhone → Build pharses → Copy Files Change the destination to "Frameworks" and click "+" button to add MirrorWorldSDK.framework to your project.

Edit UnityAppController.mm

First, add this import to head of the file:

So, finally your openUrl function should look like this:

Going Further

Great! At this point you're pretty much ready to start doing building with the Unity SDK for Mirror World. There are a few things you can do to proceed from here:

Getting Support

If you're stuck or just looking for support, you may also schedule a support call with our team.

DynamicConfiguration
CopyExpandClose

GameObject mirrorObj = new GameObject("MirrorSDK", typeof(MirrorSDK));
string apiKey = "your api key";
bool debugMode = true;
Environment environment = Environment.StagingDevnet;
MirrorSDK.InitSDK(apiKey, mirrorObj, debugMode, environment);

Edit this page on GitHub

Copyright © Mirror World, Inc. 2023

Home

Integration

Guides

API Reference