void Start() { singleton = this; // bind button events CacheAdButton.Select(); CacheAdButton.onClick.AddListener(cacheAdClicked); ShowAdButton.onClick.AddListener(showAdClicked); BackButton.onClick.AddListener(backClicked); // make sure we don't init the same Ad twice if (created) return; created = true; // create add var desc = new InterstitialAdDesc(); // Global desc.Testing = true; desc.EventCallback = eventCallback; desc.UseClassicGUI = false; desc.GUIOverrideEnabled = false; desc.UnityUI_SortIndex = 1001; // WinRT (Windows 8.1) desc.WinRT_AdAPI = InterstitialAdAPIs.AdDuplex;// NOTE: If building for WP 8.1 or Universal targets this value is used. All other WinRT values or used for Win8 // NOTE: Currently no Win8 interstisial API are supported. // WP8 (Windows Phone 8.1) desc.WP8_AdAPI = InterstitialAdAPIs.AdDuplex;// NOTE: If building for WP 8.1 or Universal targets this value is NOT used (Use the WinRT value instead). All other WP8 values are still used for WP 8.0, 8.1 and Universal. desc.WP8_AdMob_UnitID = "";// NOTE: Must set event for testing desc.WP8_AdDuplex_ApplicationKey = "";// NOTE: Must set event for testing desc.WP8_AdDuplex_UnitID = "";// NOTE: Must set event for testing // iOS desc.iOS_AdAPI = InterstitialAdAPIs.AdMob; desc.iOS_AdMob_UnitID = "";// NOTE: Must set event for testing // Android #if AMAZON desc.Android_AdAPI = InterstitialAdAPIs.Amazon; #else desc.Android_AdAPI = InterstitialAdAPIs.AdMob; #endif desc.Android_AdMob_UnitID = "";// NOTE: Must set event for testing desc.Android_Amazon_ApplicationKey = "";// NOTE: Must set event for testing // create ad ad = InterstitialAdManager.CreateAd(desc, createdCallback); }
/// <summary> /// Use to dispose of an Ad. /// NOTE: Use "ad.Cache();" to get a new Ad to show. /// </summary> /// <param name="ad"></param> public static void DisposeAd(InterstitialAd ad) { int index = getAdIndex(ad); if (index == -1) { Debug.LogError("DisposeAd Failed: InterstitialAd not found in InterstitialAdManager."); return; } var plugin = plugins[index]; plugin.Dispose(); plugins.Remove(plugin); }
private static int getAdIndex(InterstitialAd ad) { for (int i = 0; i != plugins.Count; ++i) { if (ad.plugin == plugins[i]) return i; } return -1; }
/// <summary> /// Use to create multiple Ads. /// </summary> /// <param name="descs">Your AdDesc settings.</param> /// <param name="createdCallback">The callback that fires when done.</param> /// <returns>Returns array of Ad objects</returns> public static InterstitialAd[] CreateAd(InterstitialAdDesc[] descs, InterstitialAdCreatedCallbackMethod createdCallback) { if (creatingAds) { Debug.LogError("You must wait for the last interstitial ads to finish being created!"); if (createdCallback != null) createdCallback(false); return null; } creatingAds = true; InterstitialAdManager.createdCallback = createdCallback; int startLength = plugins.Count; for (int i = 0; i != descs.Length; ++i) plugins.Add(InterstitialAdPluginAPI.New(descs[i], async_CreatedCallback)); var ads = new InterstitialAd[descs.Length]; for (int i = 0, i2 = startLength; i != descs.Length; ++i, ++i2) ads[i] = new InterstitialAd(plugins[i2]); return ads; }