Introduction

Unity is a cross platform game engine which is very popular with Mobile Game Developers. It supports all major mobile platforms. Using Unity’s IDE you can easily develop games and build them for multiple platforms.

Getting Started

This tutorial is going to help you monetize your Android and WP8 apps with Vserv.mobi. If you plan to monetize your Android game you will need the Vserv.mobi Android Unity Plugin, which is avaliable here. For Windows Phone 8 you need our WP8 Plugin which is also available on our downloads page.

Before you get started you need to make sure you have a ZoneID, it’s a unique identifier based on which Ads can be requested.

Android

Once you have downloaded the Android Plugin, you can extract it to a folder of your choice, the zip file will contain a zipped sample project, zipped plugin files and documentation. For now just extract the plugin file which will contain a unity plugin file and a cs file

You first need to import the unitypackage, for this you can right click on your Assets panel and select Import Package > Custom Package.

Next you need to add the VservPlugin.cs script from the VservUnityPlugin folder into your project. You can just drag and drop the file into your Assets panel. This script is a helper script which encapsulates all the Vserv.mobi methods into simple function calls.

You now need to select your camera and add a new script to it via the inspector panel, let’s call it Ads. Make sure it’s a C Sharp script.

Now open the Ads script in an editor of your choice. It should have the following code:

using UnityEngine;
using System.Collections;

public class Ads : MonoBehaviour {
	// Use this for initialization
	void Start () {
	}

	// Update is called once per frame
	void Update () {
	}
}

For this tutorial we are going to setup a fullscreen launch ad. So we need to add the following snippet to the Start() method.

using UnityEngine;
using System.Collections;
using VservPlugin;

public class Ads: MonoBehaviour {

    // Use this for initialization
	void Start() {
		if (Application.platform == RuntimePlatform.Android) {

            /*Show Launch Ad*/
			VservPlugin vservPlugin;
			vservPlugin = new VservPlugin();
			vservPlugin.SetShowAt(“start”);

			/*This is a test ZoneID, make sure you replace it before going live*/
			vservPlugin.DisplayAd(“8063″);
		}
	}

Note you will need to the using VservPlugin; directive too.

You will need to add the following into your AndroidManifest.xml, if you are not using a custom manifest you can create one and place it the Assets directory and then add the following.

<meta­data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version">

You also need to add the following permissions in the Manifest file:

<uses­permission android:name="android.permission.INTERNET">
<uses­permission android:name="android.permission.ACCESS_NETWORK_STATE">

Note if you are looking to get started with Unity and are looking for a HelloWorld equivalent Nokia has a very good tutorial here. While the tutorial is geared towards Windows Phone 8 the Unity section can be used for other platforms too.

Windows Phone 8

If you plan to monetize your WP8 apps you can do so by using Interstitials and Banner Ads via the Vserv.mobi WP8 SDK.

 Integration is similar to the Android integration above, a difference being that the VservPlugin class is integrated within the unity plugin. You also need to build the project once and make a few modifications within the VS project, specifically add the Windows Capabilities, some assets & initialize the VservPlugin object, these steps are described below.

Post that you can use the DisplayAd() and the RenderAd() methods to show Ads. Make sure you define the required callbacks

The capabilities that you will need to add are provided below:

ID_CAP_NETWORKING
ID_CAP_MEDIALIB_AUDIO
ID_CAP_MEDIALIB_PLAYBACK
ID_CAP_WEBBROWSERCOMPONENT
ID_CAP_IDENTITY_DEVICE
ID_CAP_IDENTITY_USER
ID_CAP_PHONEDIALER
ID_CAP_REMOVABLE_STORAGE

To initialize the VservPlugin object, add the following to the constructor of the MainPage.cs

VservPlugin.VservWP8Plugin.DSGB = DrawingSurfaceBackground;

Requesting an interstitial then becomes as easy as using the following code in the Unity script

VservWP8Plugin vservPlugin;

void Start () {
	vservPlugin = new VservWP8Plugin ();
}

void OnGUI () {
	/*This is a test ZoneID, make sure you replace it before going live*/
	vservPlugin.DisplayAd("8063");
}

If you are looking for a deeper dive into the solutions, download them from our Downloads page and check out the documentation and sample projects provided.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

nine + 3 =