Exemplo n.º 1
0
        private void PrepareAndRequestRewardedAd(int id)
        {
            var rewarded = new RewardedAd(frameworkValues.TestAds ? RewardedVideoIDTest : frameworkValues.RewardedVideoID);

            rewarded.OnAdFailedToLoad += (sender, arg) =>
            {
                MobileAdsEventExecutor.ExecuteInUpdate(() =>
                {
                    this.Log("[ADMOB] RewardedAd failed to load with message: " + arg.Message, LogLevel.FrameworkErrorInfo);
                    CoroutineHelper.InvokeWithDelay(frameworkValues.TimeAfterAdFailedToLoad, () => PrepareAndRequestRewardedAd(id));
                });
            };
            rewarded.OnUserEarnedReward += HandleRewaredAdUserEarnedReward;
            rewarded.OnAdClosed         += (sender, arg) =>
            {
                MobileAdsEventExecutor.ExecuteInUpdate(() =>
                {
                    PrepareAndRequestRewardedAd(id);
                });
            };

            var request = BuildAdRequest();

            rewarded.LoadAd(request);

            rewardedAds[id] = rewarded;
        }
Exemplo n.º 2
0
 private void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
 {
     MobileAdsEventExecutor.ExecuteInUpdate(() =>
     {
         this.Log("[ADMOB] Interstitial failed to load with message: " + args.Message, LogLevel.FrameworkErrorInfo);
         CoroutineHelper.InvokeWithDelay(frameworkValues.TimeAfterAdFailedToLoad, RequestInterstitial);
     });
 }
Exemplo n.º 3
0
 public void HandleRewardedAdClosed(object sender, EventArgs args)
 {
     Debug.Log("HandleRewardedAdClosed event received");
     MobileAdsEventExecutor.ExecuteInUpdate(() =>
     {
         RewardAd_CallBack.Invoke(ADS_CALLBACK_STATE.FAIL);
         RequestAndLoadRewardedAd();
     });
 }
Exemplo n.º 4
0
 public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args)
 {
     Debug.Log(
         "HandleRewardedAdFailedToShow event received with message: "
         + args.Message);
     MobileAdsEventExecutor.ExecuteInUpdate(() =>
     {
         RewardAd_CallBack.Invoke(ADS_CALLBACK_STATE.FAIL);
     });
 }
Exemplo n.º 5
0
 private void HandleInitCompleteAction(InitializationStatus initstatus)
 {
     // Callbacks from GoogleMobileAds are not guaranteed to be called on
     // main thread.
     // In this example we use MobileAdsEventExecutor to schedule these calls on
     // the next Update() loop.
     MobileAdsEventExecutor.ExecuteInUpdate(() => {
         statusText.text = "Initialization complete";
         RequestBannerAd();
     });
 }
Exemplo n.º 6
0
 private void HandleInitCompleteAction(InitializationStatus initstatus)
 {
     // Callbacks from GoogleMobileAds are not guaranteed to be called on
     // main thread.
     // In this example we use MobileAdsEventExecutor to schedule these calls on
     // the next Update() loop.
     MobileAdsEventExecutor.ExecuteInUpdate(() => {
         Debug.Log("Initialization complete");
         adsInitiated = true;
     });
 }
Exemplo n.º 7
0
 public void HandleOnAdClosed_InterstitialAd(object sender, EventArgs args)
 {
     MobileAdsEventExecutor.ExecuteInUpdate(() =>
     {
         Debug.Log("HandleOnAdClosed_InterstitialAd event received");
         InterstitialAd_CallBack.Invoke(ADS_CALLBACK_STATE.SUCCESS);
         Debug.Log("end call back");
         RequestAndLoadInterstitialAd();
         Debug.Log("end request");
     });
 }
    public void RequestAndLoadRewardedInterstitialAd()
    {
        statusText.text = "Requesting Rewarded Interstitial Ad.";
        // These ad units are configured to always serve test ads.
    #if UNITY_EDITOR
        string adUnitId = "unused";
    #elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-3940256099942544/5354046379";
    #elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-3940256099942544/6978759866";
    #else
        string adUnitId = "unexpected_platform";
    #endif

        // Create an interstitial.
        RewardedInterstitialAd.LoadAd(adUnitId, CreateAdRequest(), (rewardedInterstitialAd, error) =>
        {
            if (error != null)
            {
                MobileAdsEventExecutor.ExecuteInUpdate(() => {
                    statusText.text = "RewardedInterstitialAd load failed, error: " + error;
                });
                return;
            }

            this.rewardedInterstitialAd = rewardedInterstitialAd;
            MobileAdsEventExecutor.ExecuteInUpdate(() => {
                statusText.text = "RewardedInterstitialAd loaded";
            });
            // Register for ad events.
            this.rewardedInterstitialAd.OnAdDidPresentFullScreenContent += (sender, args) =>
            {
                MobileAdsEventExecutor.ExecuteInUpdate(() => {
                    statusText.text = "Rewarded Interstitial presented.";
                });
            };
            this.rewardedInterstitialAd.OnAdDidDismissFullScreenContent += (sender, args) =>
            {
                MobileAdsEventExecutor.ExecuteInUpdate(() => {
                    statusText.text = "Rewarded Interstitial dismissed.";
                });
                this.rewardedInterstitialAd = null;
            };
            this.rewardedInterstitialAd.OnAdFailedToPresentFullScreenContent += (sender, args) =>
            {
                MobileAdsEventExecutor.ExecuteInUpdate(() => {
                    statusText.text = "Rewarded Interstitial failed to present.";
                });
                this.rewardedInterstitialAd = null;
            };
        });
    }
Exemplo n.º 9
0
 private void HandleInitCompleteAction(InitializationStatus initstatus)
 {
     // Callbacks from GoogleMobileAds are not guaranteed to be called on
     // main thread.
     // In this example we use MobileAdsEventExecutor to schedule these calls on
     // the next Update() loop.
     MobileAdsEventExecutor.ExecuteInUpdate(() =>
     {
         Init_InterstitialAd();
         InitLoadRewardedAd();
         //Init_Banner();
         //InitLoadNativeAd();
     });
 }
 public void ShowRewardedInterstitialAd()
 {
     if (rewardedInterstitialAd != null)
     {
         rewardedInterstitialAd.Show((reward) => {
             MobileAdsEventExecutor.ExecuteInUpdate(() => {
                 statusText.text = "User Rewarded: " + reward.Amount;
             });
         });
     }
     else
     {
         statusText.text = "Rewarded ad is not ready yet.";
     }
 }
Exemplo n.º 11
0
    public void HandleUserEarnedReward(object sender, Reward args)
    {
        MobileAdsEventExecutor.ExecuteInUpdate(() =>
        {
            string type   = args.Type;
            double amount = args.Amount;
            Debug.Log(
                "HandleRewardedAdRewarded event received for "
                + amount.ToString() + " " + type);
            FirebaseManager.instance.LogRewarded();
            timeLastShowReward = Config.GetTimeStamp();
            RewardAd_CallBack.Invoke(ADS_CALLBACK_STATE.SUCCESS);
        });

        //RequestAndLoadRewardedAd();
    }
Exemplo n.º 12
0
    void OnInit(InitializationStatus initstatus)
    {
        // Callbacks from GoogleMobileAds are not guaranteed to be called on
        // main thread.
        // In this example we use MobileAdsEventExecutor to schedule these calls on
        // the next Update() loop.
        MobileAdsEventExecutor.ExecuteInUpdate(() =>
        {
            isInit = true;

            if (this.stateTxt != null)
            {
                this.stateTxt.text = "Initialize OK";
            }

            LoadReawrdAD();
        });
    }
Exemplo n.º 13
0
    private void Start()
    {
        // if server Ad Units is enabled then use server units:
        if (serverAdUnitsEnabled)
        {
            idBanner       = (string.IsNullOrEmpty(AdmobServerAdUnits.BannerId)) ? idBanner : AdmobServerAdUnits.BannerId;
            idInterstitial = (string.IsNullOrEmpty(AdmobServerAdUnits.InterstitialId)) ? idInterstitial : AdmobServerAdUnits.InterstitialId;
            idReward       = (string.IsNullOrEmpty(AdmobServerAdUnits.RewardId)) ? idReward : AdmobServerAdUnits.RewardId;
        }
      #if UNITY_EDITOR
        //this block is just for debugging in the editor
        string color;
        if (AdmobServer.adUnitsLoaded)
        {
            color = "yellow";
            Debug.Log(">><color=yellow>You're using <b>SERVER</b> ad units :</color>");
        }
        else
        {
            color = "orange";
            Debug.Log(">><color=orange>You're using default ad units :</color>");
        }
        Debug.Log("<color=" + color + "><b>Banner       : </b>" + idBanner + "</color>");
        Debug.Log("<color=" + color + "><b>Interstitial : </b>" + idInterstitial + "</color>");
        Debug.Log("<color=" + color + "><b>Reward      : </b>" + idReward + "</color>");
      #endif

        RequestConfiguration requestConfiguration =
            new RequestConfiguration.Builder()
            .SetTagForChildDirectedTreatment(TagForChildDirectedTreatment.Unspecified)
            .build();

        MobileAds.SetRequestConfiguration(requestConfiguration);


        MobileAds.Initialize(initstatus => {
            MobileAdsEventExecutor.ExecuteInUpdate(() => {
                if (OnInitComplete != null)
                {
                    OnInitComplete.Invoke();
                }
            });
        });
    }
Exemplo n.º 14
0
 void OnInit(InitializationStatus initstatus)
 {
     // Callbacks from GoogleMobileAds are not guaranteed to be called on
     // main thread.
     // In this example we use MobileAdsEventExecutor to schedule these calls on
     // the next Update() loop.
     MobileAdsEventExecutor.ExecuteInUpdate(() => {
         //load banner
         AdRequest request   = new AdRequest.Builder().Build();
         _banner             = new BannerView(Data.UnitId, AdSize.SmartBanner, Data.Position);
         _banner.OnAdLoaded += (sender, args) => {
             _loading = false;
             _loaded  = true;
             _onLoaded();
         };
         _banner.OnAdFailedToLoad += (sender, e) => {
             // on failed, delay 2 secs before re-loading again.
             _loadTimer = new Timer(2f);
         };
         _banner.LoadAd(request);
     });
 }
Exemplo n.º 15
0
 private void HandleRewaredAdUserEarnedReward(object sender, Reward args)
 {
     MobileAdsEventExecutor.ExecuteInUpdate(RewardPlayer);
 }