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 --------------------- .. literalinclude:: src/Unity/unityInit.cs :linenos: :language: csharp +-------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+ | **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: .. image:: images/UnityLibraryIntegration/advertpolicy.png :align: center .. literalinclude:: src/Unity/unitySetFont.cs :linenos: :language: csharp +--------------------------------+-----------------------------------------------------------------------------------------------------+ | **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. .. literalinclude:: src/Unity/unityCallbackOnAdLoaded1.cs :linenos: :language: csharp +--------------------------------+-----------------------------------------------------------------------------------------------------+ | **Delegate** | **Description** | +================================+=====================================================================================================+ | **OnAdLoaded** | Callback executed when the ad is loaded. | | | | +--------------------------------+-----------------------------------------------------------------------------------------------------+ | **OnAdLoadingFailed** | Callback executed when no ad is available or if an error occurs. | | | | +--------------------------------+-----------------------------------------------------------------------------------------------------+ .. literalinclude:: src/Unity/unityCallbackOnAdLoaded2.cs :linenos: :language: csharp +--------------------------------+-----------------------------------------------------------------------------------------------------+ | **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. .. literalinclude:: src/Unity/unityTryToLoadAd.cs :linenos: :language: csharp If you success to load an ad, you have to display it. .. literalinclude:: src/Unity/unityShowAd.cs :linenos: :language: csharp 6) Code Example .. literalinclude:: src/Unity/unityCodeExemple.cs :linenos: :language: csharp 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”. .. image:: images/UnityLibraryIntegration/IOsConfiguration.png :align: center 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: .. literalinclude:: src/Unity/androidManifest-part1.xml :linenos: :language: xml And the meta-data : .. literalinclude:: src/Unity/androidManifest-part2.xml :linenos: :language: xml 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 .. image:: images/UnityLibraryIntegration/ConfigWindows.png :align: center Second The “Capabilities” in Publishing Setting must select at least “InternetClient”, “InternetClientServer” and “PrivateNetworkServer”. .. image:: images/UnityLibraryIntegration/CapabilitiesWindows.png :align: center 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 ---------------------------------- * Download and extract the Facebook Audience Network SDK for Unity here: https://origincache.facebook.com/developers/resources/?id=FacebookSDK-current.zip * Import the package into your project by clicking on Assets => Import Package => Custom Package. * Select the AudienceNetwork.unitypackage from the AudienceNetworkSDK folder to import the plugin into your project. .. image:: images/UnityLibraryIntegration/ImportFacebook.png :align: center 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” .. image:: images/UnityLibraryIntegration/DefineSymbols.png :align: center 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 .. image:: images/UnityLibraryIntegration/IOsFlagConfiguration.png :align: center