Skip to content

Unity Plugin

Shimon Shnitzer edited this page Mar 15, 2017 · 23 revisions

Android

Installation

  1. Download or clone whole SDK-Plugins project and Extract SDK-Plugins/Unity content into a temporary directory.
  2. In your Unity project, create folder Assets/Plugin/Android.
    Copy the following from Plugins/Android into that directory:
    AndroidManifest.xml file
    libs directory (and content)
    res directory (and content)
  3. In your Unity project, create a folder Assets/Scripts.
    Copy the following file from Scripts directory into that directory:
    MobFox.cs

    Unity Project Tree
  4. In your Unity project, create a game object called MobFoxObject.
    Attach the MobFox script to it.
  5. Fill the Mob Fox Banner Inventory Hash field with your banner inventory hash.
  6. Fill the Mob Fox Interstitial Inventory Hash field with your Interstitial inventory hash.
  7. Fill the Mob Fox Game Object Name field with the name of the game object if you use one other than MobFoxObject.
  8. Fill the Top, Left fields with your location preferences.
  9. Fill the Width, Height fields with your banner size (default 320x50).

    Unity MobFox Game Object
  10. Use MobFox.ShowMobFoxBanner to display a banner ad.
  11. Use MobFox.HideMobFoxBanner, MobFox.UnhideMobFoxBanner to hide / unhide a banner ad.
  12. Use MobFox.CreateAndShowMobFoxInterstitial to display a interstitial ad.
  13. To only load the interstitial use MobFox.CreateMobFoxInterstitial.
    show the interstitial in the interstitialReady event with the MobFox.ShowMobFoxInterstitial method.
  14. Find callback functions in MobFox script to handle events:
  • banner:
    • bannerReady
    • bannerError
    • bannerClosed
    • bannerClicked
    • bannerFinished
  • interstitial:
    • interstitialReady
    • interstitialError
    • interstitialClosed
    • interstitialClicked
    • interstitialFinished
  1. By default, use of location info is disabled. To enable it, you can call MobFox.SetUseLocation(true).

Demo app

  1. Unity with MobFox demo app is available. With Banner, Interstitial and native test ads integrated, its highly recommended to use this as reference.

iOS

This feature lets you develop with unity and use MobFox's SDK.

Run Unity Demo project : https://github.com/mobfox/MobFox-iOS-SDK-Core-Lib/tree/master/Plugins/UnityDemo

Instructions:

  1. In your Unity project, create a folder Assets/Plugin/iOS. Copy to that directory the files MobFoxUnityPlugin.h and MobFoxUnityPlugin.mm from MobFox-iOS-SDK-Core-Lib/Plugins/Unity/, MobFoxSDKCore.bundle and MobFoxSDKCore.framework from MobFox-iOS-SDK-Core-Lib:
  • MobFoxSDKCore.bundle
  • MobFoxSDKCore.framework
  • MobFoxUnityPlugin.h
  • MobFoxUnityPlugin.mm
  1. In your Unity project, create a folder Assets/Scripts. Copy the following file from Scripts directory into that directory:
    MobFox.cs

    Unity Project Tree

  1. In your Unity project, create a game object called MobFoxObject. Attach the MobFox script to it.

![Unity MobFox Game Object](https://github.com/mobfox/SDK-Plugins/blob/master/Unity/Docs/img/MobFoxObject.png)
4. Fill the **‘Mob Fox Banner Inventory Hash’** field with your MobFox hash id for banners.
  1. Fill the ‘Mob Fox Interstitial Inventory Hash’ field with your MobFox hash id for interstitials.

  2. Fill the ‘Mob Fox Game Object Name’ field with the name of the game object if you use one other than ‘MobFoxObject’.

  3. Now you can use MobFox.ShowMobFoxBanner to display a banner ad, and/or MobFox.ShowMobFoxInterstitial to display an interstitial ad.

Inside the MobFox script you can find the callback functions you can use to handle events related to the banner ads (bannerReady, bannerError, bannerClosed, bannerClicked, bannerFinished) or interstitial ads (interstitialReady, interstitialError, interstitialClosed, interstitialClicked, interstitialFinished).

You can also change the location and dimensions of banner ads by altering the parameters passed in ShowMobFoxBanner_iPhone (0, 0, 320, 50) are the default.

Clone this wiki locally