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

_5
GameObject mirrorObj = new GameObject("MirrorSDK", typeof(MirrorSDK));
_5
string apiKey = "your api key";
_5
bool debugMode = true;
_5
Environment environment = Environment.StagingDevnet;
_5
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

_1
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

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

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

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

Register this activity

Register Activity

DynamicConfiguration
LoginActivity.cs
AndroidManifest.xml
Copy

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

Finally your AndroidManifest.xml file should look like this:

DynamicConfiguration
LoginActivity.cs
AndroidManifest.xml
Copy

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

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

Configure gradleTemplate.properties

Add these lines to the end of the file:

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

_2
android.useAndroidX=true
_2
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

_5
// Import statement at head of file
_5
#import <MirrorWorldSDK/MirrorWorldSDK-Swift.h>
_5
_5
// Then add this to the openUrl function
_5
[[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

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

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

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

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

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

Edit this page on GitHub

Copyright © Mirror World, Inc. 2023

Home

Tutorials

Guides

API Reference