/// <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;
        }
    }
Example #2
0
 // Update is called once per frame
 void Update()
 {
     if (!myAdMob)
     {
         //myAdMob = GetComponent<AdMobBanner>();
         myAdMob = GameObject.Find("AdManager").GetComponent <AdMobBanner>();
     }
 }
Example #3
0
    void Awake()
    {
        // keep AdManager instance alive
        DontDestroyOnLoad(this.gameObject);

        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(this.gameObject); // there is already an instance so detroy
        }
    }
    /// <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;
        }
    }
 // Creates a banner of the given type at the given position. This method requires an adUnitId and you must be updated to the new AdMob system.
 public static void createBanner( string iosAdUnitId, string androidAdUnitId, AdMobBanner type, AdMobLocation placement )
 {
     #if UNITY_IPHONE
     if( type == AdMobBanner.SmartBanner )
     {
         if( Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight )
             AdMobBinding.createBanner( androidAdUnitId, AdMobBannerType.SmartBannerLandscape, (AdMobAdPosition)placement );
         else
             AdMobBinding.createBanner( androidAdUnitId, AdMobBannerType.SmartBannerPortrait, (AdMobAdPosition)placement );
     }
     else
     {
         AdMobBinding.createBanner( androidAdUnitId, (AdMobBannerType)type, (AdMobAdPosition)placement );
     }
     #elif UNITY_ANDROID
     AdMobAndroid.createBanner( iosAdUnitId, (AdMobAndroidAd)type, (AdMobAdPlacement)placement );
     #endif
 }
 // Creates a banner of the given type at the given position. This method does not take an adUnitId and will work with legacy AdMob accounts.
 public static void createBanner( AdMobBanner type, AdMobLocation placement )
 {
     createBanner( null, null, type, placement );
 }
Example #7
0
 // Start is called before the first frame update
 void Start()
 {
     theBall = GameObject.FindGameObjectWithTag("Ball");
     myAds   = GetComponent <AdMobBanner>();
 }
Example #8
0
 // Start is called before the first frame update
 void Start()
 {
     rb2d = GetComponent <Rigidbody2D>();
     Invoke("goBall", 2);
     myAdMob = GetComponent <AdMobBanner>();
 }
    /// <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);
            }
        }
    }