Unity plugin for AdDeals
This is a cross-platform Unity plugin for AdDeals's SDKs. It combines and supports three platforms together: Windows(UWP), iOS, and Android.
System requirements:
- Unity v5.5.4.p5 or later
- Vistual Studio 2017 or later
- Xcode 10 or later
- Android Studio 3.2.1 or later
Integrate
- In order to get your AppID & AppKey you must first create an account on http://www.addealsnetwork.com
- Then add your iOS / Android / Windows 10 apps and you will get 1 AppID / AppKey for each app version.
- Download the AdDeals plugin from SDKBox repo.
- Drag
Assets\AdDeals\AdDeals.prefab
onto your game scene. - Call AdDeals SDK APIs. Please check out the sample codes in
Assets\AdDeals\Sample\Test.cs
:
AdDeals.AdDealsWrapper.Init("AppID", "AppKey");
int adType = AdDealsWrapper.AdTypeInterstitial; // 1:interstitial 2: rewarded video
AdDeals.AdDealsWrapper.ShowAd(adType);
Windows UWP build
- Support the lastest AdDeals SDK for Windows: AdDealsUniversalSDKW81.
- Using .Net ScriptBackend, please export the UWP project (project) in Unity with the following settings:
- Or using il2cpp ScriptBackend, please export the project in Unity 2018 or later with following settings:
- Please enable
InternetClient
:- Unity 2019+ UWP capabilities path:
Project Settings
>Player
>Publisher settings
>Capabilities
.
- Unity 5.5+ UWP capabilities path:
PlayerSetting
->Universal Windows Platform
->Publishing Setting
->Capabilities
.
- Unity 2019+ UWP capabilities path:
- For Unity 5.x: if you want to build UWP application, please use Unity 5.5.4p5 or later. you can download Unity Patch Releases.
- If you want to pass Windows App Certification Kit test, we recommend you use Windows SDK
10.0.19041.0
and.NET Native tool chain
("VS 2019"->"Project Properties -> Build -> Compile with .NET Native tool chain")
Optional: compatible with Microsoft Ads using Windows Store Native
We offer a UnityRT project to integrate Windows Store Native
.
The main purpose of the following steps is to add UnityRT to the unity exported solution and invoke Windows Store Native
in this UnityRT project.
now please follow the following to integrate Windows Store Native
(make sure you have completed everything above).
- follow
Windows Store Native
's documentation, InstitialAd, BannerAd, finish it's integrate steps. - In Vistual Studio, open the main project exported from Unity.
- Add the
UnityRT
project into Visual Studio:File
->Add
->Existing Project...
->SelectYour_Main_Project/UnityRT/UnityRT.vcxproj
- Change project dependencies: make your main project dependent on
UnityRT
, and makeUnityRT
dependent onIl2CppOutputProject
. (Note: the main project in these sample screenshots is called AdDeals.)
- Add reference to UnityRT in your main project.
- Modify
MainPage.xaml.cs
:
...
namespace AdDeals
{
...
public sealed partial class MainPage : Page
{
...
public MainPage()
{
...
BridgeBootstrapper.SetUWPBridge(new UWPBridge());
UnityRT.App.Start(GetSwapChainPanel()); // invoke UnityRT project
}
...
}
...
}
- Modify
UnityRT/App.cpp
(fromWindows Store Native
Ad module document: InstitialAd, BannerAd)
void App::Start(Windows::UI::Xaml::Controls::SwapChainPanel^ panel)
{
// AppInit
InterstitialAdManager::Initialise();
BannerAdManager::Initialise(panel);
}
- Add Reference to
Microsoft Advertising SDK for XAML
in UnityRT - Check
Windows Store Native
's document, and invoke in Unity Side. - Run and Test.
iOS build
- From Unity, first export to an iOS project. Next build and run it using Xcode.
- Support iOS 8+.
-
you must add a script phase to Xcode
AdDeals.framework
- new script phase, and name it
StripAdDeals
- new script phase, and name it
2. add follow script
strip_invalid_archs() {
binary="$1"
# Get architectures for current target binary
binary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)"
# Intersect them with the architectures we are building for
intersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\n' | sort | uniq -d)"
# If there are no archs supported by this binary then warn the user
if [[ -z "$intersected_archs" ]]; then
echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)."
STRIP_BINARY_RETVAL=0
return
fi
stripped=""
for arch in $binary_archs; do
if ! [[ "${ARCHS}" == *"$arch"* ]]; then
# Strip non-valid architectures in-place
lipo -remove "$arch" -output "$binary" "$binary" || exit 1
stripped="$stripped $arch"
fi
done
if [[ "$stripped" ]]; then
echo "Stripped $binary of architectures:$stripped"
fi
STRIP_BINARY_RETVAL=1
}
binary="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AdDeals.framework/AdDeals"
# Strip invalid architectures so "fat" simulator / device frameworks work on device
if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then
strip_invalid_archs "$binary"
fi
and the script phase should be look like follow
Android build
- From Unity, first export the application to a Gradle project. Next build and run it using Android Studio. Do NOT build APK directly in Unity.
- Support Android SDK v15+.
- For Unity 5.x: please edit
YOUR_EXPORTS_PROTECT_ROOT/build.gradle
with the following configurations:
...
android {
...
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName '0.1'
...
}
...
}
...
API
Methods
- Initialize the AdDeals SDK.
void AdDeals.AdDealsWrapper.Init(String appID, String appKey);
- Set privacy policy consent.
void AdDeals.AdDealsWrapper.SetConsent(int consent);
- Check availability.
void AdDeals.AdDealsWrapper.IsCachedAdAvailable(int adType, int uiOrientation);
-
uiOrientation
: when used with adType, lets you indicating if you would prefer getting a video ad whose content is horizontal (most common case) or vertical. Be aware that you aren't giving here a restriction, just a preference. Otherwise, simply pass the AdDealsWrapper.UIOrientationUnset value. -
Cache Ad.
void AdDeals.AdDealsWrapper.CacheAd(int adType, string placementID, int uiOrientation);
placementID
: optional AdDeals ad placement ID generated for your app (on demand). If not wanted to be used, leave it empty ("").-
uiOrientation
: when used with adType, lets you indicating if you would prefer getting a video ad whose content is horizontal (most common case) or vertical. Be aware that you aren't giving here a restriction, just a preference. Otherwise, simply pass the AdDealsWrapper.UIOrientationUnset value. -
Show Ad.
void AdDeals.AdDealsWrapper.ShowAd(int adType, string placementID, int uiOrientation);
placementID
: optional AdDeals ad placement ID generated for your app (on demand). If not wanted to be used, leave it empty ("").uiOrientation
: when used with adType, lets you indicating if you would prefer getting a video ad whose content is horizontal (most common case) or vertical. Be aware that you aren't giving here a restriction, just a preference. Otherwise, simply pass the AdDealsWrapper.UIOrientationUnset value.
Note: placementID is an advanced feature and in most cases you can just leave it "". In case you want to use placementIDs you should contact addeals@ahead-solutions.com
Callback
SDK trigers feedback events (callbacks) notifying the client app when action are performed (either by SDK or end user; typically when there is an ad being shown/clicked/closed) or when failures occur. Following is the exhaustive listing of exposed callbacks :
public static event AdAvailableHandler AdAvailableEvent;
public static event AdEventHandler SDKNotInitializedEvent;
public static event AdEventHandler ShowAdVideoRewardedGrantedEvent;
public static event AdEventHandler ShowAdSuccessEvent;
public static event AdEventStringHandler ShowAdFailedEvent;
public static event AdEventHandler CacheAdSuccessEvent;
public static event AdEventStringHandler CacheAdFailedEvent;
public static event AdEventHandler MinDelayBtwAdsNotReachedEvent;
public static event AdEventHandler AdClosedTap;
public static event AdEventHandler AdClickedTap;
public static event AdEventHandler AdManagerInitSDKSuccess;
public static event AdEventStringHandler AdManagerInitSDKFailed;
public static event AdEventHandler AdManagerConsentSuccess;
public static event AdEventStringHandler AdManagerConsentFailed;
public static event AdEventHandler AdManagerAppDownloadSourceDetected;
public static event AdEventHandler AdManagerAppSessionSourceDetected;
here is a sample to subscribe SDK init success:
- define a function
void AdManagerInitSDKSuccess() {
//addeals init success
}
- let the upper function subscribe SDK init success event
AdDeals.AdDealsWrapper.AdManagerInitSDKSuccess += AdManagerInitSDKSuccess;
- when sdk init success, AdManagerInitSDKSuccess will be called.
Constants
UI Orientation
AdDealsWrapper.UIOrientationUnset;
AdDealsWrapper.UIOrientationPortrait;
AdDealsWrapper.UIOrientationLandscape;
Ad type
AdDealsWrapper.AdTypeInterstitial;
AdDealsWrapper.AdTypeRewardedVideo;
Consent
public const int UserConsentNotApplicable;
public const int UserConsentRevoke;
public const int UserConsentGrant;
Verification
Tested on the follow Unity versions:
- Unity v2018.2.16f
- Unity v2018.1.0f2
- Unity v2017.1.2f1
- Unity v2017.1.0p5
- Unity v5.5.4p5
Sample Project
https://github.com/sdkbox/AdDeals-Unity-Sample
Issues
- if you got follow error when import this unitypackage, it's ok, you can ignore it.
Unity Knowledge Point
When you export UWP project form unity, you wll see Develop build
in the right corner of the screen. You can hide it by changing the build setting to "Master" on Visual studio.
https://forum.unity.com/threads/unity-uwp-development-build-stamp.450192/