Unity Package integration
Download and integrate the LevelPlay Unity Plugin into your project to enable ad mediation and monetization features.
Thời gian đọc 4 phútCập nhật lần cuối 2 ngày trước
Step 1. Add LevelPlay to your Unity project
You can install the LevelPlay package using two main methods:
- [Recommended] Add the Ads Mediation package to your project by navigating to Window → Package Manager in Unity. Look for “Ads Mediation” and click the install button. You can also add the package by its name:
com.unity.services.levelplay - Or, Download Unity Plugin Version 9.2.0 (.unitypackage) and import it into your Unity project.
Step 2. Initialize the SDK
If you haven't done so already, go to the LevelPlay Platform and create a new app. Once done, use your App Key to initialize the SDK:- Import the namespace: At the top of your C# script, include the namespace:
using Unity.Services.LevelPlay; - Initialize the SDK: Inside your Start() method, register event listeners and initialize the SDK:
It is important to register OnInitFailed and OnInitSuccess before initializing LevelPlay as they provide you with important insight: OnInitSuccess – triggered when LevelPlay initialized successfully. After you receive this callback, you can start showing ads in your app. OnInitFailed – triggered when LevelPlay failed to initialize and therefore ads will not show. We recommend trying to initialize LevelPlay later (when internet connection is available, or when the failure reason is resolved).public void Start() { // Register OnInitFailed and OnInitSuccess listeners LevelPlay.OnInitSuccess += SdkInitializationCompletedEvent; LevelPlay.OnInitFailed += SdkInitializationFailedEvent; // SDK init LevelPlay.Init("ThisIsYourAppKey");}
Set UserID
You can pass in a User ID when initializing LevelPlay. This is useful if you're trying to use Ad Quality's User Journey, or if you're using server-to-server callbacks to reward your users.LevelPlay.Init("ThisIsYourAppKey", "UserId");
Step 3. LevelPlay Network Manager
The LevelPlay Network Manager window is a one stop shop for all things LevelPlay. You can find it in Unity’s top navigation bar, under Ads Mediation. From here, you can:- Update your LevelPlay SDK.
- Install & update your preferred Ad Networks. Once installed, you’ll need to configure each ad network separately. Learn more.
- Get your app’s Info.plist automatically updated with SKAdNetwork IDs according to the ad networks you have installed.
Android
To apply your changes and download the relevant ad network artifacts, you'll need to use a resolver. Go to: Assets > Mobile Dependency Manager > Android Resolver > Resolve You should do this after each change in the LevelPlay Network Manager. If you're using Gradle, you can avoid downloading the network artifacts into your project. Instead, the artifacts will be added to your Gradle file during the compilation.
To enable this process, follow these steps:
- Go to: Edit > Project Settings > Player > Android > Publishing Settings
- Enable Custom Main Gradle Template
- Go to: Assets > Mobile Dependency Manager > Android Resolver > Settings
- Select “Patch mainTemplate.gradle”
- Save your changes, by pressing “OK”
Step 4. Additional setup
iOS
SKAdNetwork support
If you have SKAdNetwork ID automation disabled, you must manually include the SKAdNetwork ID for each of your installed networks in your app property list file (Info.plist) to enable the display of ads while using SDK 7+:
<key>SKAdNetworkItems</key><array> <dict> <key>SKAdNetworkIdentifier</key> <string>su67r6k2v3.skadnetwork</string> </dict></array>
App transport security settings
- Add in a dictionary called 'NSAppTransportSecurity'. Make sure you add this dictionary on the 'Top Level Key'.
- Inside this dictionary, add a Boolean called 'NSAllowsArbitraryLoads' and set it to YES.
- Make sure that your info.plist does not contain any other exceptions besides 'NSAllowsArbitraryLoads', as this might create a conflict.
- Find more information on ATS here.
Android
Apps using Android 13+ (API level 33+) will need to declare a Google Play services normal permission in the manifest file as follows:Read more about Google Advertising ID changes here.<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
Step 5. Verify your integration
The LevelPlay package provides an easy way to verify that your integration was completed successfully with its integration test suite. Test your app’s integration, verify platform setup, and review ads related to your configured networks. To enable the test suite in your app, call the following before initializing the SDK:After successfully initializing LevelPlay, launch the test suite by calling:LevelPlay.SetMetaData("is_test_suite", "enable");
For more details and an implementation example of the LevelPlay integration test suite navigate to this article.LevelPlay.LaunchTestSuite();