Skip to main content

Player Network SDK Integration - Unity

Prerequisites

caution

The version of each SDK plugin used by the game (including the version used by the game launcher) must be consistent.If the game needs to access multiple versions of the Player Network SDK simultaneously, or only one component requires an upgrade, please contact the Player Network assistant.

Enter the PlayerNetwork SDK Download Page and choose the appropriate engine and platform to download the PlayerNetwork SDK.For details, refer to the PlayerNetwork SDK Download Guide.

Step 1: Install the SDK

Engine version support

Unity 2021 ~ Unity 6

Version Requirements

androidx
minSdkVersion: 21
targetSdkVersion: 34
compileSdkVersion: 34

If you integrate with LINE, minSdkVersion must be upgraded to 24.

If you integrate with Discord, minSdkVersion must be upgraded to 23.

Note before project submission for review: Starting from SDK V1.24.00, Google has added foreground service permissions declaration.If this declaration is not approved by Google, resubmitting for review may take about a week.For more information, see Specify Foreground Service Types.

1. Add Player Network SDK to your project

  1. Extract the SDK package.
  2. Copy INTLSDK folder to the project's Assets folder.
  3. Merge the Plugins folder of Player Network SDK into the project's Plugins folder.
Player Network SDK package
├─INTLSDK       // Player Network SDK CS scripts that offer APIs and callbacks
│ ├─Editor // Editor scripts for Player Network SDK including Player Network SDK XUPorter
│ └─Scripts // Scripts for Player Network SDK that include INTLCore and other plugin scripts
├─LevelInfinite // LI PASS APIs
├─Plugins // Plugins for Player Network SDK for various platforms
│ ├─Android
│ ├─iOS
│ ├─MacOS
│ └─Windows~
├─Symbols // Symbol table *.so files for Player Network SDK
└─UnionAdapter // UnionAdapter APIs that adapt to both MSDK and Player Network SDK
INTLSDK/Scripts/INTLCore
├─INTLSDK
│ ├─Editor
│ └─Scripts
│ ├─INTLConfig
| └─INTLCore
| ├─Editor // INTLCore PostProcess.cs / PreProcess.cs files for different platforms
| | ├─INTLCoreAndroidPostProcess.cs
| | ├─INTLCoreiOSPostProcess.cs
| | ├─INTLCoreMacOSPostProcess.cs
| | ├─INTLCoreWindowsPostProcess.cs
| | └─INTLCoreWindowsPreProcess.cs
| └─Scripts // INTLCore scripts
| ├─INTLAPI.cs // Player Network SDK APIs
| ├─INTLConfig.cs // Player Network SDK data structures
| ├─INTLDefine.cs // Player Network SDK static strings
| ├─INTLErrorCode.cs // Player Network SDK error codes
| ├─Modules
| └─Utils
├─LevelInfinite
├─Plugins
├─Symbols
└─UnionAdapter
INTLSDK/Script/INTLConfig
├─INTLSDK
│ ├─Editor
│ └─Scripts
│ ├─INTLConfig
| | └─Editor // Configuration files for Player Network SDK, PostProcess.cs files, and encryption tools
| | ├─Encrypt
| | | ├─decrypt // Decryption tool for Player Network SDK for INTLConfig.ini
| | | ├─Decrypt.exe // Decryption tool for Player Network SDK for INTLConfig.ini
| | | ├─encrypt // Encryption tool for Player Network SDK for INTLConfig.ini
| | | ├─Encrypt.exe // Encryption tool for Player Network SDK for INTLConfig.ini
| | | ├─EncryptConfig.ini // File to enable or disable encryption for INTLConfig.ini in Player Network SDK
| | | ├─INTLConfigINI.cs
| | | ├─INTLConfigINIEditor.cs
| | | └─INTLEditorTools.cs
| | ├─INTLConfigAndroidPostProcess.cs
| | ├─INTLConfigiOSPostProcess.cs
| | ├─INTLConfigMacOSPostProcess.cs
| | ├─INTLConfigSwitchPreProcess.cs
| | ├─INTLConfigWindowsPostProcess.cs
| | └─Resources // Configurations for Player Network SDK
| | ├─APASConfig.ini // Configuration file for APAS device level
| | └─INTLConfig.ini // Main configuration file for Player Network SDK
| └─INTLCore
├─LevelInfinite
└─Plugins

2. Loading required permissions and plug-ins

note

If your game has not yet created a custom Android activity, see Create a custom activity.

Add Player Network SDK code for loading permissions, libraries, and plugins into the custom launch activity (Android games request permissions and load plugins here).

Add code for loading libraries
MainActivity.java
static {
try {
System.loadLibrary("INTLFoundation");
System.loadLibrary("INTLCore");
System.loadLibrary("INTLUnityAdapter");
}
catch (Exception e) {
e.printStackTrace();
}
}
Register activity lifecycle
MainActivity.java
import com.intlgame.api.INTLSDK;
import android.content.Intent;
import android.os.Bundle;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// add this line
INTLSDK.initialize(MainActivity.this);
}

@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// add this line
INTLSDK.onNewIntent(intent);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// add this line
INTLSDK.onActivityResult(requestCode, resultCode, data);
}

@Override
public void onRequestPermissionsResult(int arg0, String[] arg1, int[] arg2) {
super.onRequestPermissionsResult(arg0, arg1, arg2);
// add this line
INTLSDK.onRequestPermissionsResult(arg0, arg1, arg2);
}
Load dynamic permissions
Get dynamic permissions via code

Add the following code to request permissions dynamically:

import android.app.Activity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import java.util.ArrayList;
import java.util.List;

private void RequestPermission(Activity activity, List<String> permissionList, int requestCode) {
if (null != activity && null != permissionList) {
List<String> permissionNeeded = new ArrayList();

for (int i = 0; i < permissionList.size(); ++i) {
String permission = (String) permissionList.get(i);
if (null != permission && 0 != ContextCompat.checkSelfPermission(activity.getApplicationContext(), permission)) {
permissionNeeded.add(permission);
}
}

if (permissionNeeded.size() > 0) {
ActivityCompat.requestPermissions(activity, (String[]) permissionNeeded.toArray(new String[permissionNeeded.size()]), requestCode);
}
}
}

private void RequestDynamicPermissions() {
List<String> permissions = new ArrayList();
permissions.add("android.permission.INTERNET");
permissions.add("android.permission.READ_PHONE_STATE");
this.RequestPermission(this, permissions, 100);
}

Call RequestDynamicPermissions:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// add this line
RequestDynamicPermissions();
INTLSDK.initialize(MainActivity.this);
}
Notched screen compatibility settings

After Android P, Android provides a standard API for notched screens.However, for Android O devices, different vendors have different implementation logics.Player Network SDK provides unified C++ API and Java API to support various Android O devices from Xiaomi, Huawei, Samsung, VIVO, and OPPO.

Player Network SDK includes an INTLUnityAdapter module, allowing Unity games to make unmanaged calls from C# to the C++ API.For more information, see Asynchronous Notched Screen Info Read.

Generally, the full-screen aspect ratio of mobile phones is greater than 2.1.To avoid black borders, users must set android.max_aspect to above 2.1.
For Huawei and Xiaomi phones using the Android Oreo operating system, users must configure AndroidManifest.

<!--Supports full-screen aspect ratio of 2.4 to adapt to the future 21:9 ultra-widescreen-->
<meta-data android:name="android.max_aspect" android:value="2.4" />
<!--Xiaomi O version definition: Whether to use ear areas (high-risk area)-->
<!--values:
none: ear areas not rendered in portrait or landscape mode,
portrait: ear areas rendered in portrait mode,
landscape: ear areas rendered in landscape mode,
portrait|landscape: ear areas rendered in both portrait and landscape mode
-->
<meta-data android:name="notch.config" android:value="portrait|landscape"/>
<!--Huawei O version definition: App pages use notch area-->
<meta-data android:name="android.notch_support" android:value="true"/>

For games that use Android API to fetch notched screen safe area information, please add the following configuration:

Add the following code in MainActivity.

MainActivity.java
import android.os.Build;
import android.view.WindowManager;
import android.view.View;


private void setFullScreen()
{
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);// Set full screen
int systemUiVisibility = 0;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
systemUiVisibility = this.getWindow().getDecorView().getSystemUiVisibility();
int flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
systemUiVisibility |= flags;
getWindow().getDecorView().setSystemUiVisibility(systemUiVisibility);
}
// P version is allowed to use the notch area
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = this.getWindow().getAttributes();
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
this.getWindow().setAttributes(lp);
}
}

Call setFullScreen() here.

MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// add this line
setFullScreen();
this.RequestDynamicPermissions();
INTLSDK.initialize(this);
}

In PlayerSetting, select Render outside safe area.

Image: Android Unity Setting

3. Generate JAR package

note

Before generating the JAR package, replace all com.intlgame.unity.MainActivity in Plugins/Android/AndroidManifest.xml with the actual package name of the game, such as com.example.myapp.MainActivity.

Player Network SDK uses Gradle to generate the JAR package.Gradle configuration files include third-party SDK version numbers as well as dependencies required by Player Network SDK and third-party channels.The game needs to add necessary dependencies based on the required plugins.

mainTemplate.gradle and INTLCore.mainTemplate.gradle are Player Network SDK Gradle configuration files.Please update the Gradle configuration according to the game requirements.

Unity 2018
FileFile Path
mainTemplate.gradlePlugins/Android
INTLCore.mainTemplate.gradlePlugins/Android/Gradle

There are at least two updates:

  1. Merge the mainTemplate.gradle from your game into Player Network SDK's mainTemplate.gradle, and keep content marked by Player Network SDK.
mainTemplate.gradle
buildscript {
repositories {**ARTIFACTORYREPOSITORY**
// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ Player Network SDK ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
maven {
url "https://mirrors.tencent.com/nexus/repository/maven-public/"
}
maven {
url "https://mirrors.tencent.com/repository/maven/thirdparty"
}
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ Player Network SDK ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
mavenCentral()
google()
jcenter()
}

dependencies {
// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ Player Network SDK ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
classpath 'com.android.tools.build:gradle:4.0.1'
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ Player Network SDK ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
**BUILD_SCRIPT_DEPS**
}
}

allprojects {
repositories {**ARTIFACTORYREPOSITORY**
// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ Player Network SDK ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
maven {
url "https://mirrors.tencent.com/nexus/repository/maven-public/"
}
maven {
url "https://mirrors.tencent.com/repository/maven/thirdparty"
}
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ Player Network SDK ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
mavenCentral()
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
  1. Follow the integration instructions for third-party channels.
  2. Replace the {placeholder} text in INTLCore.mainTemplate.gradle with the value from the INTLConfig.ini configuration file.
INTLCore.mainTemplate.gradle
android {
compileSdkVersion rootProject.ext.common.compileSdkVersion
buildToolsVersion rootProject.ext.common.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.ext.common.minSdkVersion
targetSdkVersion rootProject.ext.common.targetSdkVersion
multiDexEnabled rootProject.ext.common.minSdkVersion < 21

manifestPlaceholders = [
"FACEBOOK_APPID" : "{INTL_FACEBOOK_APP_ID}",
"GOOGLE_APPID" : '{INTL_GOOGLE_APP_ID}',
"FACEBOOK_CLIENT_TOKEN" : "{INTL_FACEBOOK_CLIENT_TOKEN}",
'GOOGLEPGS_APPID' : '{INTL_GOOGLEPGS_APPID}',
'VK_APPID' : '{INTL_VK_APP_ID}',
'GARENA_APP_ID' : '{INTL_GARENA_APP_SDK_ASSIGN_ID}',
'QQ_APPID' : '{INTL_QQ_APP_ID}',
'GOOGLE_CLIENT_ID' : '{INTL_GOOGLE_CLIENT_KEY_ANDROID}',
'DISCORD_APP_ID' : '{INTL_DISCORD_APP_ID}',
'DISCORD_REDIRECT_SCHEME' : '{INTL_DISCORD_REDIRECT_SCHEME}',
'DISCORD_REDIRECT_HOST' : '{INTL_DISCORD_REDIRECT_HOST}',
'DISCORD_REDIRECT_PATH' : '{INTL_DISCORD_REDIRECT_PATH}',
'DMM_LOGIN_ACTIVITY_DATA_SCHEME': '{INTL_DMM_LOGIN_ACTIVITY_DATA_SCHEME}',
'WEBVIEW_TASK_AFFINITY' : '',
'VNG_GG_APP_ID' : '{INTL_VNG_GG_APP_ID}',
'VNG_GG_CLIENT_TOKEN' : '{INTL_VNG_GG_CLIENT_TOKEN}',
]
}
}

Unity 2019 and above
FileFile Path
mainTemplate.gradlePlugins/Android
baseProjectTemplate.gradlePlugins/Android
launcherTemplate.gradlePlugins/Android
INTLCore.mainTemplate.gradlePlugins/Android/Gradle
INTLCore.baseProjectTemplate.gradlePlugins/Android/Gradle
INTLCore.launcherTemplate.gradlePlugins/Android/Gradle

There are at least two updates:

  1. Merge the mainTemplate.gradle, baseProjectTemplate.gradle, and launcherTemplate.gradle from your game into the corresponding Gradle files in Player Network SDK, and keep content marked by Player Network SDK.
mainTemplate.gradle
// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ Player Network SDK - INTLCore ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
dependencies {
implementation "androidx.appcompat:appcompat:1.4.0-alpha03"
implementation "androidx.annotation:annotation:1.0.0"
implementation "com.google.android.gms:play-services-ads-identifier:17.0.0"
// Migrated to :app
// implementation "com.google.android.play:core:1.10.0"
}
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ Player Network SDK - INTLCore ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ Player Network SDK - INTLFacebook ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
dependencies {
implementation "androidx.annotation:annotation:1.0.0"
implementation "com.facebook.android:facebook-login:16.1.3"
implementation "com.facebook.android:facebook-share:16.1.3"
implementation "com.facebook.android:facebook-core:16.1.3"
implementation "com.facebook.android:facebook-gamingservices:16.1.3"
implementation "com.facebook.android:facebook-common:16.1.3"
implementation "com.facebook.android:facebook-applinks:16.1.3"
}
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ Player Network SDK - INTLFacebook ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

// ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ Player Network SDK ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
apply from: "$rootDir/INTL.Gradle/INTLCore.mainTemplate.gradle"
// ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ Player Network SDK ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
  1. Follow the integration instructions for third-party channels.
  2. Replace {placeholder} in INTLCore.launcherTemplate.gradle with values from the INTLConfig.ini configuration file.
INTLCore.mainTemplate.gradle
android {
compileSdkVersion rootProject.ext.common.compileSdkVersion
buildToolsVersion rootProject.ext.common.buildToolsVersion

defaultConfig {
minSdkVersion rootProject.ext.common.minSdkVersion
targetSdkVersion rootProject.ext.common.targetSdkVersion
multiDexEnabled rootProject.ext.common.minSdkVersion < 21

manifestPlaceholders = [
"FACEBOOK_APPID" : "{INTL_FACEBOOK_APP_ID}",
"FACEBOOK_CLIENT_TOKEN" : "{INTL_FACEBOOK_CLIENT_TOKEN}",
"GOOGLE_APPID" : '{INTL_GOOGLE_APP_ID}',
'GOOGLEPGS_APPID' : '{INTL_GOOGLEPGS_APPID}',
'VK_APPID' : '{INTL_VK_APP_ID}',
'GARENA_APP_ID' : '{INTL_GARENA_APP_SDK_ASSIGN_ID}',
'QQ_APPID' : '{INTL_QQ_APP_ID}',
'GOOGLE_CLIENT_ID' : '{INTL_GOOGLE_CLIENT_KEY_ANDROID}',
'DISCORD_APP_ID' : '{INTL_DISCORD_APP_ID}',
'DISCORD_REDIRECT_SCHEME' : '{INTL_DISCORD_REDIRECT_SCHEME}',
'DISCORD_REDIRECT_HOST' : '{INTL_DISCORD_REDIRECT_HOST}',
'DISCORD_REDIRECT_PATH' : '{INTL_DISCORD_REDIRECT_PATH}',
'DMM_LOGIN_ACTIVITY_DATA_SCHEME': '{INTL_DMM_LOGIN_ACTIVITY_DATA_SCHEME}',
'WEBVIEW_TASK_AFFINITY' : '',
'VNG_GG_APP_ID' : '{INTL_VNG_GG_APP_ID}',
'VNG_GG_CLIENT_TOKEN' : '{INTL_VNG_GG_CLIENT_TOKEN}',
]
}
}

4. Player Network SDK Configuration

note

When manually modifying the INTLConfig.ini file, please contact the Player Network support to confirm that the changes are as expected. For details, see SDK Config Instructions.

Please configure according to the instructions in INTLConfig.ini.

5. Initialize Player Network SDK

Player Network SDK must be initialized before integrating third-party channels.For more details, see Initialize SDK.For more details, see Initialize SDK.

using INTL;// import INTL namespace

void InitializeINTLSDK()
{
INTLAPI.IsDebug = true; // Set SDK to Debug mode to print logs; default is false
INTLAPI.InitSDK();
}

Step 2: Verify Successful Integration of Player Network SDK

  1. Modify the configuration under the INTL Log node in the INTLConfig.ini file.
[INTL Log]
LOG_LEVEL = 1
LOG_ENCRYPT_ENABLE = 0
LOG_COMPRESS_ENABLE = 0
LOG_CONSOLE_OUTPUT_ENABLE = 1
LOG_FILE_OUTPUT_ENABLE = 1
  1. Run the program, when the log displays Init INTL SDK success., it indicates successful integration.