Since the introduction of Unity3d for Windows Phone 8 and Windows Store Apps in July 2013 developers are asking for a way to integrate AdDuplex into their awesome games.
At the moment of this writing no AdDuplex plugin exists in the Unity Asset Store. This is one of the high priority tasks on our to-do list, but it’s not there yet. However, it is possible to add AdDuplex control to your game manually and quite a few developers have already implemented it. This is done by simply building the project and adding some code using Visual Studio. The trick to achieve communication between Unity and the AdDuplex ad control is to provide public events via Unity scripts for the XAML page code-behind to subscribe to.
Following is a specific example on how to add and communicate with the AdControl from a Unity game for Windows Phone 8. Communication is illustrated by implementing a capability to hide the ads from your Unity script.
- In Unity create a specific C# script and name it Interop.cs. It’s purpose is to provide a public event handler that can be used to communicate with the actual XAML code-behind.
- Create a method that fires the CollapseAdControl event. Fill the script with the following code:
- Build the Unity project (SHIFT + CTRL + B)
- Find and open the generated Visual Studio Solution
- Go to Tools -> Library Package Manager -> Package Manager Console
- Run the following command to install AdDuplex dependencies:
- Add the adControl to your game:
- Hook up to Interop.CollapseAdControl event in the MainPage.xaml.cs
- Add the event handler code