Unity Library Integration

Introduction

The library described in this document aims to broadcast messages of advertisers. These are native ads dedicated for video games and totally integrated in the game experience.

Our format of native advertising is based on four key values:

  • It respects the game graphics
  • It appears in a positive moment of achievement for the player
  • It congratulates and rewards the player with a non-incentivized content of the game (item, currency, bonus…)
  • It offers to the player the possibility to click on a link or a button. The click is optional, there is no incentive to force the action.

The design of the window is achieved by the Playtem team, based on graphical elements provided by the game publisher.

Getting started

1) Requirement

We support Unity 5.3 or later for smartphones and tablets running on IOS and Android and UWP 10 for Windows:

  • IOS 8.0+
  • Android 4.0.3 (API 15) and architecture ARMv7 and x86
  • Universal Windows Platform 10 (WSA on Unity)

2) Prerequisites

Before starting the integration of the SDK in your game, you have to check that:

  • You have provided Playtem sufficient artworks to design the ad windows according to your game,
  • If your game includes virtual items or currency, check that you have defined with the Playtem team which item(s) will be offered as a reward with the ads. Our engine can manage different rewards randomly offered to players.

If it has been acted that a reward will be offered, you have to send to Playtem information about the selected reward(s): name of each item (if available in different languages) and one picture per item,

  • Discuss with Playtem where and when you plan to display the ad message,
  • Check that you have received from Playtem your apiKey for both testing platform and production platform.

Now, you are ready to start the integration. Follow the 3 next steps to add the SDK into your game.

3) Add the library to your project

First at all, you have to download and import the PlaytemAdNetwork.unitypackage.

link Here : http://documentation.playtem.com/sdk/playtem-unity-sdk.unitypackage

To Import the package into your project click on Assets => Import Package => Custom Package

4) Initialize Playtem

1
2
// Initialize a new ad
PlaytemNetwork playtemNetwork = new PlaytemNetwork(string ApiKey, string UserId);
Parameters Description
apiKey: string

Mandatory. It is your Playtem game’s Api key. This key is provided by our technical team.

Example Values: “1G4c-hJ76e”

userId: string

Mandatory. It is a unique id for your player who initiates the call. The easiest way is to use your own ids.

This anonymous Id will be used to credit items.

Example Values: “A948”

The ad message will use your own fonts to print texts. Your fonts have to be present in the Resources folder. There are 5 placements requiring to define a font:

../_images/advertpolicy.png
1
2
3
4
// Initialize the font  
playtemNetwork.SetFont(Rendering.TextSection.Title, "ClearSans-Bold", 40, Color.black);
playtemNetwork.SetFont(Rendering.TextSection.Reward, "ClearSans-Bold", 35, Color.yellow);
playtemNetwork.SetFont(Rendering.TextSection.Button, "ClearSans-Bold", 30, Color.white);
SetFont parameters Description
type: Rendering.TextSection

Mandatory. The placement for which we want to set the font.

Values: “Title”, “Reward”, “Description”, “Legal”, “Button”

fontName: string

Mandatory. The exact name of the font in the Resources folder

Example Values: “ClearSans-Bold”

fontSize: int

Mandatory. The size of the font. Here are the usual value but you have to check the size depending on your font:

Example Values: “Title = 40”, “Reward = 35”, “Description = 30”, “Legal = 20”, “Button = 30”

fontColor: Color

Mandatory. The color of the font.

Example Values: “Color.black”, “new Color(0, 0, 0)”

5) Retrieve an ad

First, you have to define the callbacks.

1
2
3
4
5
// Add action on delegate

playtemNetwork.OnAdLoaded = delegate () { Debug.Log("Playtem ad load"); };

playtemNetwork.OnAdLoadingFailed = delegate (string message) { Debug.Log("Playtem loading failed : " + message); };
Delegate Description
OnAdLoaded Callback executed when the ad is loaded.
OnAdLoadingFailed Callback executed when no ad is available or if an error occurs.
1
2
3
4
5
// Add action on delegate

playtemNetwork.OnAdClosed= delegate () { Debug.Log("Playtem ad load"); };

playtemNetwork.OnRewarded= delegate (string message) { Debug.Log("Playtem reward ID: " + message); };
Delegate Description
OnAdClosed Callback executed when the ad is closed.
OnRewarded Callback executed when the ad is rewarded.

Then, you have to load the ad.

1
2
// Call an ad
playtemNetwork.TryToLoadAd();

If you success to load an ad, you have to display it.

1
2
// Display the ad
playtemNetwork.ShowAd();
  1. Code Example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
this.playtemNetwork = new PlaytemNetwork("1G4chJ76e", " A948");
playtemNetwork.OnAdLoaded = delegate ()
{
    Debug.Log("Show ad");
    playtemNetwork.ShowAd();
};
playtemNetwork.OnAdLoadingFailed = delegate (string message)
{
    Debug.Log("Loading ad fail");
};
playtemNetwork.OnRewarded = delegate (string message)
{
    Debug.Log("Reward the player with the id :" + message);
};
playtemNetwork.OnAdClosed = delegate ()
{
    Debug.Log("Ad closed");
};
playtemNetwork.TryToLoadAd();

Build your application

iOS

Ensure your iOS deployment target is set to iOS 8.0 or newer.

Select Edit => Project Settings => Player.

Then click on the iOS tab and edit the “Target iOS Version”.

../_images/IOsConfiguration.png

Android

If you already use google play services you have to delete the “Plugins” folder in Assets/Playtem folder and add to your AndroidManifest the following permission:

1
2
3
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

And the meta-data :

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

Univeral Windows Plateform (WSA on Unity)

To use our SDK for Windows Apps (WSA) you have to configure 2 option in the player setting.

Select Edit => Project Setting => Player.

First the “Configuration” in Other setting you must have the scripting Backend set to .NET

../_images/ConfigWindows.png

Second The “Capabilities” in Publishing Setting must select at least “InternetClient”, “InternetClientServer” and “PrivateNetworkServer”.

../_images/CapabilitiesWindows.png

Facebook Audience Network

Playtem has an agreement with Facebook in order to get native advertising from the Facebook network. If you want to take benefit from this agreement, you have to add the Facebook Audience Network library during the integration process. In case you already have integrated the Facebook Audience Network SDK into your game, you just have to jump to the chapter 2 ‘Configuration for Unity’.

1) Add the library to your project

../_images/ImportFacebook.png

2) Configuration for unity

You have to set the “Scripting define Symbols”. Select Edit => Project Settings => Player. Add in Other Settings => Scripting define Symbols “PLAYTEM_FACEBOOK”

../_images/DefineSymbols.png

3) Configuration for XCode project (iOS only)

When you build the XCode project for smartphone or tablt devices from Unity, you may get the following link errors: Undefined symbols for architecture arm64: “_xmlXPathFreeeObject”, referenced from: lxml::xpath::object::object(_xmlXPathObject*) in FBAudienceNetwork(FNFMediaPresentationDescription.o) This is because AudienceNetwork iOS Unity package has reference to libxml, and currently Unity Native Plugin does not provide API to add dependent libraries to be linked for the iOS project later. Therefore, you would need to add libxml in your XCode project manually by following way. Add ‘-lxml2’ to ‘Other Linker Flags’ in Build Settings page in your project

../_images/IOsFlagConfiguration.png