// public void DestroyInterstitial() // Not supported by NeatPlug!

    /// <summary>
    /// Loads a banner advert into memory.
    /// </summary>
    /// <param name="AdType">Admob banner ad type.</param>
    /// <param name="AdLayout">Admob ad position.</param>
    /// <param name="DisplayImmediately">If set to <c>true</c> display the banner immediately when it has finished loading.</param>
    /// <param name="AdChildDirected">Ad child directed.</param>
    public void LoadBanner(AdmobAd.BannerAdType AdType, AdmobAd.AdLayout AdLayout, bool DisplayImmediately = false, AdmobAd.TagForChildrenDirectedTreatment AdChildDirected = AdmobAd.TagForChildrenDirectedTreatment.Unset)
    {
        if (!EnableAdMob)
        {
            return;
        }

        // Get the name of the current method
        string MethodName = "LoadBanner";

        DebugLog(MethodName + " called");

        // Update the state items (Values used to determine if the action in this method should be ran)
        ActionState[MethodName].UpdateItems(new List <bool>()
        {
            !BannerIsLoading, !BannerIsReady, !BannerIsVisible
        });

        // Check if we can perform the action for the current method
        if (CanPerformAction(MethodName, ActionState[MethodName].items))
        {
            // Mark the banner as loading
            BannerIsLoading = true;

            // If we want to display the banner as soon as it's loaded then mark the wanted visible variable as true
            BannerWantedVisible = DisplayImmediately;

            // Load a banner ad marking it as hidden, this script will handle showing the banner
            AdIns.LoadBannerAd(AdType, AdLayout, Vector2.zero, true, new Dictionary <string, string>(), AdChildDirected);

            BannerInMemoryType   = AdType;
            BannerInMemoryLayout = AdLayout;
        }
        else
        {
            // We already have a banner loading, ready or visible.. if we tried to load the same banner type maybe reposition or simply ShowBanner would be better here
            if (AdType == BannerInMemoryType)
            {
                if (AdLayout != BannerInMemoryLayout)
                {
                    RepositionBanner(0, 0, AdLayout);
                }

                if (DisplayImmediately)
                {
                    ShowBanner();
                }
            }
        }
    }
    private IEnumerator RetryBannerLoad()
    {
        yield return(new WaitForSeconds(5f));

        DebugLog("Retrying banner load!");

        if (!BannerIsLoading)
        {
            BannerInMemoryType   = default(AdmobAd.BannerAdType);
            BannerInMemoryLayout = default(AdmobAd.AdLayout);
            return(false);
        }

        LoadBanner(BannerInMemoryType, BannerInMemoryLayout, false, AdmobAd.TagForChildrenDirectedTreatment.Unset);
    }
Esempio n. 3
0
    // Load a banner advert from Google
    public void loadBanner(AdmobAd.BannerAdType adSize, AdmobAd.AdLayout adPosition, bool displayImmediately = false)
    {
        // Make sure there isn't already a banner advert loading or ready
        if (!isBannerLoading && !isBannerReady)
        {
            // Load the banner advert with adSize and adPosition as requested
            AdmobAd.Instance().LoadBannerAd(adSize, adPosition);

            // Set the banner loading variable so we know we have a banner loading
            isBannerLoading = true;
        }

        if (displayImmediately)
        {
            showBanner(false, true);
        }
    }
    /// <summary>
    /// Remove the banner from memory. (Required if you want to load a new banner ad type)
    /// </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(AdmobAd.BannerAdType);
        BannerInMemoryLayout = default(AdmobAd.AdLayout);

        DebugLog("Destroying banner!");

        // Unload the banner from memory
        AdIns.DestroyBannerAd();
    }
    private IEnumerator RetryBannerLoad()
    {
        yield return new WaitForSeconds(5f);

        DebugLog("Retrying banner load!");

        if(!BannerIsLoading){
            BannerInMemoryType = default(AdmobAd.BannerAdType);
            BannerInMemoryLayout = default(AdmobAd.AdLayout);
            return false;
        }

        LoadBanner(BannerInMemoryType, BannerInMemoryLayout, false, AdmobAd.TagForChildrenDirectedTreatment.Unset);
    }
    // public void DestroyInterstitial() // Not supported by NeatPlug!
    /// <summary>
    /// Loads a banner advert into memory.
    /// </summary>
    /// <param name="AdType">Admob banner ad type.</param>
    /// <param name="AdLayout">Admob ad position.</param>
    /// <param name="DisplayImmediately">If set to <c>true</c> display the banner immediately when it has finished loading.</param>
    /// <param name="AdChildDirected">Ad child directed.</param>
    public void LoadBanner(AdmobAd.BannerAdType AdType, AdmobAd.AdLayout AdLayout, bool DisplayImmediately = false, AdmobAd.TagForChildrenDirectedTreatment AdChildDirected = AdmobAd.TagForChildrenDirectedTreatment.Unset)
    {
        if(!EnableAdMob)
            return;

        // Get the name of the current method
        string MethodName = "LoadBanner";

        DebugLog(MethodName + " called");

        // Update the state items (Values used to determine if the action in this method should be ran)
        ActionState[MethodName].UpdateItems(new List<bool>(){ !BannerIsLoading, !BannerIsReady, !BannerIsVisible });

        // Check if we can perform the action for the current method
        if(CanPerformAction(MethodName, ActionState[MethodName].items)){
            // Mark the banner as loading
            BannerIsLoading = true;

            // If we want to display the banner as soon as it's loaded then mark the wanted visible variable as true
            BannerWantedVisible = DisplayImmediately;

            // Load a banner ad marking it as hidden, this script will handle showing the banner
            AdIns.LoadBannerAd(AdType, AdLayout, Vector2.zero, true, new Dictionary<string, string>(), AdChildDirected);

            BannerInMemoryType = AdType;
            BannerInMemoryLayout = AdLayout;
        } else {
            // We already have a banner loading, ready or visible.. if we tried to load the same banner type maybe reposition or simply ShowBanner would be better here
            if(AdType == BannerInMemoryType){
                if(AdLayout != BannerInMemoryLayout)
                    RepositionBanner(0, 0, AdLayout);

                if(DisplayImmediately)
                    ShowBanner();
            }
        }
    }
    /// <summary>
    /// Remove the banner from memory. (Required if you want to load a new banner ad type)
    /// </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(AdmobAd.BannerAdType);
        BannerInMemoryLayout = default(AdmobAd.AdLayout);

        DebugLog("Destroying banner!");

        // Unload the banner from memory
        AdIns.DestroyBannerAd();
    }