Advertisement
Guest User

Untitled

a guest
May 27th, 2014
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. // (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
  2.  
  3. using System;
  4. using UnityEngine;
  5.  
  6. #if UNITY_ANDROID
  7. namespace HutongGames.PlayMaker.Actions
  8. {
  9.     [ActionCategory("AdMob")]
  10.     [Tooltip("Displays a banner Ad - Android Only")]
  11.     public class ShowInterstitial : FsmStateAction
  12.     {
  13.  
  14.         [Tooltip("Would you like this banner at the top of your sceen or the bottom.")]
  15.         public FsmString interstitialAdID;
  16. #if !UNITY_EDITOR
  17.         private AdMobPlugin adMobPlugin_;
  18. #endif
  19.  
  20.         public override void OnEnter()
  21.         {
  22. #if !UNITY_EDITOR      
  23.             string adID = AdMobHelper.GetInstance.GetID();
  24.             try {
  25.                
  26.                 AdMobPlugin.InterstitialLoaded += HandleInterstitialLoaded;
  27.                 GameObject go = GameObject.Find ("AdMob Android");
  28.                 if(go) {
  29.                     adMobPlugin_ = (AdMobPlugin)go.GetComponent("AdMobPlugin") as AdMobPlugin;
  30.                     adMobPlugin_.CreateBanner(adID, AdMobPlugin.AdSize.LEADERBOARD, true, interstitialAdID.Value);
  31.                     adMobPlugin_.RequestInterstitial();
  32.                 }
  33.                 else {
  34.                     Debug.LogError("Put the AdMob Android prefab in your scene");
  35.                     Finish();
  36.                 }
  37.             }
  38.             catch(Exception e) {
  39.                 Debug.LogError(e.ToString());
  40.                 Finish();
  41.             }
  42. #else
  43.             Finish();
  44. #endif
  45.         }
  46.  
  47.         #if !UNITY_EDITOR
  48.         public override void OnExit ()
  49.         {
  50.             AdMobPlugin.InterstitialLoaded -= HandleInterstitialLoaded;
  51.         }
  52.        
  53.         void HandleInterstitialLoaded() {
  54.  
  55.             adMobPlugin_.ShowInterstitial();
  56.             Finish();
  57.         }
  58.         #endif
  59.     }
  60. }
  61. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement