We are seeing more and more Unity games joining our cross promotion network. Some of them are housing AdDuplex banners and some are already benefiting from the newly introduced interstitial ads.
Interstitial ads are best applicable to games, since they occupy the whole screen and are usually displayed during natural pauses in app’s flow. It is quite a trivial task to include AdDuplex Interstitial ads into a game that is created using Mono Game, XAML or some other tool that depend on a straightforward Windows Phone page manipulation in Visual Studio (or Microsoft Blend for that matter). For Unity3D developers it might not be as simple.
Configuring the Unity project
- Register your Windows Phone app in AdDuplex system and write down your Ad unit ID and App key.
- In Unity create a specific C# script and name it Interop.cs. It’s purpose is to provide a public event handlers that can be used to communicate with the actual XAML code-behind.
- To load and show interstitial ad in Unity script call Interop.ShowInterstitial().
- To pre-load interstitial ad in Unity call Interop.LoadInsterstitial(). This is not required, since Interop.ShowInterstitial() can also download an ad, but it can be used to shorten loading times.
- Subscribe to Interop.OnInterstitialClosed event to know when the user closes the ad. Be careful for what you do in the callback, because a lot of Unity engine functionality is non thread safe.
- Build the Unity project (SHIFT + CTRL + B) into a Windows Phone 8 project
Configuring the build in Visual Studio
- Find and open the generated Visual Studio Solution
- Go to Tools -> NuGet Package Manager -> Package Manager Console (or Tools -> Library Package Manager -> Package Manager Console when in Visual Studio 2012 or below)
- Run the following command in the console to install AdDuplex dependencies: Install-Package AdDuplexWP8 (If you are building to Windows Phone XAML 8.1 (Universal) package please refer to Windows Phone 8.1 XAML AdDuplex Interstitial Ad Installation and Usage and change the namespaces accordingly.
- Add the following line to the Application_Launching (or OnLaunched if you are on Windows Phone 8.1 XAML Universal build) method in the App.xaml.cs file. Don’t forget to use your real AppKey!
- Open the MainPage.xaml.cs file and create a member of InterstitialAd type.
- Locate the constructor method public MainPage() and add some code to subscribe to Interop events.
- Finally add code to manage the interstitials according to Interop commands and initialize the ad control. Don’t forget to fill in your AdUnitId here.
This is it. You can now build and test the project. Here is a sample project for Unity 5 that waits for a user tap to show an ad – GitHub AdDuplexUnity sample.
If you have ideas on improving this guide or need some help just drop a comment below or contact us via support.adduplex.com