/// <summary> /// Remove the banner from memory. (Required if you want to load a new banner ad type, however it's automatic when calling to load a new banner) /// </summary> public void DestroyBanner() { if (!EnableAdMob) { return; } // Mark the banner properties as false as the banner is now destroyed BannerWantedVisible = false; BannerIsLoading = false; BannerIsReady = false; BannerIsVisible = false; BannerInMemoryType = default(AdSize); BannerInMemoryLayout = default(AdPosition); DebugLog("Destroying banner!"); // Unload the banner from memory switch (BannerAdType) { case BannerAdTypeList.Default: AdMobBanner.Destroy(); break; case BannerAdTypeList.NativeExpressAds: AdMobNativeBanner.Destroy(); break; } }
/// <summary> /// Hides a banner advert, will also cancel a banner advert from showing if one is loaded. /// </summary> /// <param name="IsOverlay">Set to <c>true</c> if you want to hide the banner while opening an overlaying screen (such as the backscreen) and want to revert the banner ad status later.</param> public void HideBanner(bool IsOverlay = false) { if (!EnableAdMob) { return; } // If this is an overlaying screen (e.g backscreen) then we'll want to return to the previous banner state when we close it if (IsOverlay) { BannerOverlayDepth++; if (BannerOverlayDepth == 1) { BannerPrevState = BannerWantedVisible; } } DebugLog("Hiding banner!"); // Mark wanted visible as false so if the banner ad hasn't loaded yet it'll make sure it isn't shown when loaded BannerWantedVisible = false; BannerIsVisible = false; // Hide the banner advert from view (This does not unload it from memory) switch (BannerAdType) { case BannerAdTypeList.Default: if (AdMobBanner != default(BannerView)) { AdMobBanner.Hide(); } break; case BannerAdTypeList.NativeExpressAds: if (AdMobNativeBanner != default(NativeExpressAdView)) { AdMobNativeBanner.Hide(); } break; } }
/// <summary> /// Shows a banner advert if one is loaded in memory. /// </summary> public void ShowBanner(bool ForceShow = false) { if (!EnableAdMob) { return; } // Get the name of the current method string MethodName = "ShowBanner"; DebugLog(MethodName + " called"); // Check if we're calling ShowBanner because we're returning from an overlay screen which hid the banner if (BannerOverlayDepth > 0 && !ForceShow) { // Decrease the overlay depth by 1 BannerOverlayDepth--; // If the overlay depth is still above 0 then there must still be some overlays open if (BannerOverlayDepth > 0) { return; } // There isn't any more overlaying menus open, return to the previous banner ad state BannerWantedVisible = BannerPrevState; DebugLog("Banner wanted set to prev state: " + BannerPrevState); } else { BannerWantedVisible = true; } if (!BannerWantedVisible) { return; } // Update the state items (Values used to determine if the action in this method should be ran) ActionState[MethodName].UpdateItems(new List <bool>() { !BannerIsVisible }); // Check if we can perform the action for the current method if (CanPerformAction(MethodName, ActionState [MethodName].items)) { if (BannerIsReady) { // Show the banner switch (BannerAdType) { case BannerAdTypeList.Default: AdMobBanner.Show(); break; case BannerAdTypeList.NativeExpressAds: AdMobNativeBanner.Show(); break; } } else { LoadBanner(true, true); } } }