/// <summary>
        /// Triggered when an interstitial is loaded and ready to be shown
        /// </summary>
        private void InterstitialLoaded()
        {
            if (interstitialAd.IsValid())
            {
                interstitialIsLoaded = true;
                interstitialDidClose = false;
                if (debug)
                {
                    Debug.Log(this + " " + "Interstitial Loaded");
                    ScreenWriter.Write(this + " " + "Interstitial Loaded");
                }
                currentRetryInterstitial = 0;
            }
            else
            {
                if (debug)
                {
                    Debug.Log(this + " " + "Interstitial Loaded but is invalid");
                    ScreenWriter.Write(this + " " + "Interstitial Loaded but is invalid");
                }

                //try again to load an interstitial video
                if (currentRetryInterstitial < maxRetryCount)
                {
                    currentRetryInterstitial++;
                    if (debug)
                    {
                        Debug.Log(this + " " + "RETRY " + currentRetryInterstitial);
                        ScreenWriter.Write(this + " " + "RETRY " + currentRetryInterstitial);
                    }
                    Invoke("LoadInterstitial", reloadTime);
                }
            }
        }
示例#2
0
        protected override bool DoPreLoadAd()
        {
#if UNITY_IOS
            if (m_InterstitialAd != null)
            {
                return(false);
            }
#endif

            if (m_InterstitialAd == null)
            {
                m_InterstitialAd = new InterstitialAd(m_Config.unitID);
                m_InterstitialAd.Register(UIMgr.S.uiRoot.gameObject);
                m_InterstitialAd.InterstitialAdDidLoad            = HandleOnAdLoaded;
                m_InterstitialAd.InterstitialAdDidFailWithError  += HandleOnAdFailedToLoad;
                m_InterstitialAd.InterstitialAdWillLogImpression += HandleOnAdOpened;
                m_InterstitialAd.InterstitialAdDidClick          += HandleOnAdClick;
                m_InterstitialAd.InterstitialAdDidClose          += HandleOnAdClosed;
            }

            if (m_InterstitialAd.IsValid())
            {
                return(false);
            }

            m_InterstitialAd.LoadAd();

            return(true);
        }
示例#3
0
    private void LoadingInterstitialAdSuccessful()
    {
        isInterstitialLoading  = false;
        isInterstitialAdLoaded = true;

        string isAdValid = interstitialAd.IsValid() ? "valid" : "invalid";

        StatusShow.instance.ShowAdStatus("Interstitial Ad loaded and " + isAdValid);
    }
示例#4
0
    // Load button
    public void LoadInterstitial()
    {
        statusLabel.text = "Loading interstitial ad...";

        // Create the interstitial unit with a placement ID (generate your own on the Facebook app settings).
        // Use different ID for each ad placement in your app.
        interstitialAd = new InterstitialAd("YOUR_PLACEMENT_ID");

        interstitialAd.Register(gameObject);

        // Set delegates to get notified on changes or when the user interacts with the ad.
        interstitialAd.InterstitialAdDidLoad = delegate()
        {
            Debug.Log("Interstitial ad loaded.");
            isLoaded = true;
            didClose = false;
            string isAdValid = interstitialAd.IsValid() ? "valid" : "invalid";
            statusLabel.text = "Ad loaded and is " + isAdValid + ". Click show to present!";
        };
        interstitialAd.InterstitialAdDidFailWithError = delegate(string error)
        {
            Debug.Log("Interstitial ad failed to load with error: " + error);
            statusLabel.text = "Interstitial ad failed to load. Check console for details.";
        };
        interstitialAd.InterstitialAdWillLogImpression = delegate()
        {
            Debug.Log("Interstitial ad logged impression.");
        };
        interstitialAd.InterstitialAdDidClick = delegate()
        {
            Debug.Log("Interstitial ad clicked.");
        };
        interstitialAd.InterstitialAdDidClose = delegate()
        {
            Debug.Log("Interstitial ad did close.");
            didClose = true;
            if (interstitialAd != null)
            {
                interstitialAd.Dispose();
            }
        };

#if UNITY_ANDROID
        /*
         * Only relevant to Android.
         * This callback will only be triggered if the Interstitial activity has
         * been destroyed without being properly closed. This can happen if an
         * app with launchMode:singleTask (such as a Unity game) goes to
         * background and is then relaunched by tapping the icon.
         */
        interstitialAd.interstitialAdActivityDestroyed = delegate() {
            if (!didClose)
            {
                Debug.Log("Interstitial activity destroyed without being closed first.");
                Debug.Log("Game should resume.");
            }
        };
#endif

        // Initiate the request to load the ad.
        interstitialAd.LoadAd();
    }