Download
Download AdSystemPluginMopub Unity Package
Usage
Ad networks are configured in the morefunadapi key in a game’s manifest. The Ad network placement status updates will get IAdSystemListener interface on the AdSystemAdapter. The preloadInterstitial and preloadRewardVideo keys were added in DarkMatter 4.1.0 and they allow you to enable or disable the pre-loading of ads. When disabled, ads will be loaded when the showAd method is called.
NOTE: If pre-loading is disabled the isAdReady methods will always return true
Integration
-
Download and import the AdSystemPluginMoPub.unitypackage into your project.
-
In Unity, search for and select the root hive scriptable object, then click the find nodes and link button. This will add the AdsNodeMoPub.cs into the hive initialization sequence. After you should see the “AdsMoPub” (AdsNodeMoPub) in the controlled nodes list. A note that if your using a version of Unity < 5.6 then you may need to click off and back on the asset for the node to show up in the list.
-
In Hope, add the “morefunadapi” node to the game’s manifest. See the manifest keys section of the documentation site or see bellow for an example for the Magic Test App.
-
NOTE: When installed DARKMATTER_ADS_PLUGIN_MOPUB will automatically get added to the “Scripting Define Symbols”, if the symbol isn’t getting added you may need to force a recompile by making a change to a script file. If you remove the plugin you’ll need to manually remove the define from your project to get rid of it.
Integration - iOS
- MRaid file: Extract the AdsMRAIDFix.zip into the Assets/DarkMatterAdPlugins/MoPub/Editor/iOS/Ads/res folder of your Unity project. You should now have the proper MRAID file with this folder structure: Assets/DarkMatterAdPlugins/MoPub/Editor/iOS/Ads/res/.dontcompile/MRAID.bundle/mraid.js
Integration - Android
- Android Manifest: In your applications AndroidManifest.xml you’ll need to add the following activities and permissions. Some permissions are optional see the permission chart bellow. Some sections bellow have been collapsed for brevity.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferExternal" android:versionCode="1" android:versionName="1.0">
<!-- Will set the application launch activity to the custom AdsUnityActivity which is required for some network callbacks -->
<activity android:name="com.magmic.darkmatter.ads.AdsUnityActivity" android:label="@string/app_name">
</activity>
<!-- MoPub requirements-->
<activity android:name="com.mopub.mobileads.MoPubActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.common.MoPubBrowser" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.RewardedMraidActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<!-- Ad network requirements -->
<activity
android:name="com.tapjoy.TJAdUnitActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<activity
android:name="com.tapjoy.mraid.view.ActionHandler"
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:name="com.tapjoy.mraid.view.Browser"
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:name="com.tapjoy.TJContentActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:hardwareAccelerated="true" />
<activity android:name="com.vungle.publisher.VideoFullScreenAdActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
<activity android:name="com.vungle.publisher.MraidFullScreenAdActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
<activity android:name="com.vungle.publisher.FlexViewAdActivity"
android:configChanges="keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
<activity
android:name="com.mediabrix.android.core.AdViewActivity"
android:configChanges="orientation|screenSize|keyboard"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
</activity>
<activity
android:name="com.mediabrix.android.core.ClickOutActivity"
android:configChanges="orientation|screenSize|keyboard"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
</activity>
<activity android:name="com.applovin.adview.AppLovinInterstitialActivity" />
<activity android:name="com.applovin.adview.AppLovinConfirmationActivity" />
<activity android:name="com.chartboost.sdk.CBImpressionActivity"
android:excludeFromRecents="true"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity android:name="com.adcolony.sdk.AdColonyInterstitialActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:hardwareAccelerated="true"/>
<activity android:name="com.adcolony.sdk.AdColonyAdViewActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:hardwareAccelerated="true"/>
</application>
<!-- mopub, vungle, tapjoy, mediabrix, applovin, chartboost, adcolony -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- mopub, vungle, tapjoy, mediabrix, applovin, chartboost optional, adcolony optional, admob optional -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
<!-- mopub, vungle, tapjoy, mediabrix, applovin, chartboost, adcolony -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- mopub optional, vungle optional, mediabrix optional, admob optional -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- mopub optional, vungle optional, mediabrix optional -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- tapjoy optional, chartboost optional-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- tapjoy optional, chartboost optional-->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- mediabrix optional, adcolony optional -->
<uses-permission android:name="android.permission.VIBRATE" />
<!-- mediabrix optional -->
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
</manifest>
- Build Gradle: in your mainTemplate.gradle add the following entries to each section, some sections have been concatenated for brevity.
Define your gradle version (if you build with a different version change it here)
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
Add the some of the remote repos for some of the ad networks.
allprojects {
repositories {
...
maven { url "https://maven.google.com" }
maven { url "https://adcolony.bintray.com/AdColony" }
maven { url "https://s3.amazonaws.com/moat-sdk-builds" }
}
}
Add the ad network dependencies
dependencies {
...
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-annotations:25.3.1'
compile ('com.google.android.gms:play-services-ads:11.8.0')
compile('com.mopub:mopub-sdk:4.17.0@aar') {
transitive = true
}
compile 'com.adcolony:sdk:3.2.1'
compile 'com.facebook.android:audience-network-sdk:4.27.1@aar'
}
Some general Android build configurations
android {
...
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
defaultConfig {
...
multiDexEnabled true
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
}
...
}
...
buildTypes {
release {
...
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt', "proguard-user.txt"
...
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/rxjava.properties'
}
dexOptions {
javaMaxHeapSize "4g"
}
}
- Proguard: In your proguard-user.txt file add the following to allow for build export minification
# DarkMatter Proguard Config
-keepclassmembers class com.magmic.darkmatter.** { public *; }
-keepclassmembers class com.mopub.** { public *; }
-keep public class com.mopub.**
-keep class * extends com.mopub.mobileads.CustomEventBanner {}
-keep class * extends com.mopub.mobileads.CustomEventInterstitial {}
-keep class * extends com.mopub.nativeads.CustomEventNative {}
# ***** Vungle start *****
-dontwarn com.vungle.**
-dontnote com.vungle.**
-keep class com.vungle.** { *; }
-keep class javax.inject.*
# GreenRobot
-dontwarn de.greenrobot.event.util.**
# RxJava
-dontwarn rx.internal.util.unsafe.**
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
-keep class rx.schedulers.Schedulers { public static <methods>; }
-keep class rx.schedulers.ImmediateScheduler { public <methods>; }
-keep class rx.schedulers.TestScheduler { public <methods>; }
-keep class rx.schedulers.Schedulers { public static ** test(); }
# MOAT
-dontwarn com.moat.**
-keep class com.moat.** { public protected private *; }
# Retrofit
-dontwarn okio.**
-dontwarn retrofit2.Platform$Java8
# ***** Vungle end *****
# ***** Mediabrix start *****
-keepattributes Signature
-keep class com.mediabrix.** { *; }
-keep class com.moat.** { *; }
-keep class mdos.** { *; }
-dontwarn com.mediabrix.**
-dontwarn com.moat.**
-dontwarn mdos.**
# ***** Mediabrix end *****
# ***** Tapjoy start *****
-keep class com.tapjoy.** { *; }
-keep class com.moat.** { *; }
-keepattributes JavascriptInterface
-keepattributes *Annotation*
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-keep class com.google.android.gms.ads.identifier.** { *; }
-dontwarn com.tapjoy.**
# ***** Tapjoy end *****
# ***** Chartboost start *****
-keep class com.chartboost.** { *; }
# ***** Chartboost end *****
# ***** AdColony start *****
# For communication with AdColony's WebView
-keepclassmembers class * {
@android.webkit.JavascriptInterface <methods>;
}
# Keep ADCNative class members unobfuscated
-keepclassmembers class com.adcolony.sdk.ADCNative** {
*;
}
# **** AdColony end *****
# ***** Facebook start *****
-keep class com.facebook.** {
*;
}
# ***** Facebook end *****
Manifest Example
"morefunadapi": {
"preloadInterstitial": false,
"preloadRewardVideo": false,
"networks": {
"mopub": {
"videoadunitid": "16177a5b77be4b42a3a398dc8619cc46",
"adunitid": "da8e8e01de6c475e8be20cad18e234ef"
},
"unityads": {
"debug": true,
"rewardVideoZoneId": "rewardedVideoZone",
"gameid": "25665",
"enabled": true,
"zoneid": "defaultVideoAndPictureZone"
},
"tapjoy": {
"debug": "true",
"rewardplacementid": "vid_ad",
"enabled": true,
"appsdkkey": "brZB5ODUS8iPDixMDTtwDAECNtWSz48GxLSUtoEATnqLKX0ko0129NbhrmDo",
"placementid": "fs_ad"
},
"mediabrix": {
"adtype": "Android_Rally_Testapp",
"rewardadtype": "Android_Rewards_Testapp",
"enabled": true,
"appid": "wR8mDWZDOz",
"debug": true
},
"facebook": {
"enabled": true,
"placementid": "1117319031623420_1117362761619047"
},
"aol": {
"enabled": true,
"debug": true,
"siteid": "8a809417015555974dad9d50086a016d",
"placementid": "interstitial"
},
"applovin": {
"enabled": true,
"sdkkey": "NpMrXXgQ-MPdymFwGZvHkkU_cZJofz81nUtI1Xk0u8dqutl9RdQALw9zUTl8QuACN1UOTDPRL1GDv_NLdpV-ie"
},
"vungle": {
"enabled": true,
"appid": "59ee0f825eea3ba93e0016e0",
"placementid": "DEFAULT22494",
"rewardplacementid": "REWARDE73026",
"placementids": [
"DEFAULT22494",
"REWARDE73026"
]
},
"chartboost": {
"appsig": "dd2d41b69ac01b80f443f5b6cf06096d457f82bd",
"enabled": true,
"appid": "4f7b433509b6025804000002"
},
"adcolony": {
"rewardzoneid": "vz231776df08b04b23a2",
"zoneid": "vz4cdb31000d064f0da5",
"enabled": true,
"zoneids": [
"vz4cdb31000d064f0da5",
"vz231776df08b04b23a2"
],
"appid": "app25e243050a674db3a3"
},
"admob": {
"enabled": true,
"adunitid": "ca-app-pub-3940256099942544/1033173712"
}
},
"verbose": true,
"placements": {
"main_menu": {
"control": {
"interval_type": "Impressions",
"enabled": true,
"interval": 2
}
},
"rewarded_video": {
"control": {
"interval_type": "Impressions",
"enabled": true
}
}
},
"storename": "google",
"sendAnalytics": true
}
Custom Flags - DEPRECATED
NOTE - DEPRECATED, use the IAdSystemListener callbacks for ad status instead.
When you want to display an interstitial, simply make the call to show an ad with a placement tag string and the library will display an interstitial when one is ready. The placement tag is used to control the frequency of ad presented. You can check to see if an interstitial is ready to be shown, and if one is not ready yet you can continue on with your game as normal.
if (Ads.adReady) {
Ads.ShowAd("YOUR_PLACEMENT_KEY");
}
When you want to trigger a rewarded video ad, make a similar call with a placement tag string. Again, check to see if a rewarded video is ready to be shown.
if (Ads.rewardedVideoAdReady) {
Ads.ShowRewardedVideoAd("YOUR_REWARD_PLACEMENT_KEY");
}
Android Permissions
The three required permissions for the sdk to function are INTERNET, WRITE_EXTERNAL_STORAGE, ACCESS_NETWORK_STATE. All other permissions are optional and can be omitted. A note that if you remove optional permissions it may affect your apps ad network monetization.
| Permission | Required | Optional |
|---|---|---|
| INTERNET | mopub, vungle, tapjoy, mediabrix, applovin, chartboost, adcolony | |
| WRITE_EXTERNAL_STORAGE | mopub, vungle, tapjoy, mediabrix, applovin | chartboost, adcolony, admob |
| ACCESS_NETWORK_STATE | mopub, vungle, tapjoy, mediabrix, applovin, chartboost, adcolony | |
| ACCESS_COARSE_LOCATION | mopub, vungle, mediabrix, admob | |
| ACCESS_FINE_LOCATION | Mopub, vungle, mediabrix | |
| ACCESS_WIFI_STATE | tapjoy, chartboost | |
| READ_PHONE_STATE | tapjoy, chartboost | |
| VIBRATE | mediabrix, adcolony | |
| WRITE_CALENDAR | mediabrix |
Package for distribution
To make a package of the AdSystemPluginMoPub
- First make sure you either have no folder selected or the root asset folder selected in the Unity Project explorer.
- Then select Assets -> Export.
- Under DarkMatterAdPlugins folder select the MoPub folder, make sure only this folder is selected all dependencies external to this folder will be added manually by the person integrating the plugin.
- Take the exported .unitypackage file and zip it up with the DarkMatter/proj.unity/docs/files/AdsMRAIDFix.zip file. This zip file is the full AdSystemPluginMoPub package.