示例#1
0
    //make button interactable if video ad is ready

    /*void Update()
     * {
     *  if (rewardAd.IsLoaded())
     *  {
     *      watchAd.interactable = true;
     *  }
     * }*/

    void RequestRewardedAd()
    {
#if UNITY_ANDROID
        rewardId = "ca-app-pub-3940256099942544/5224354917";
#else
        rewardId = null;
#endif
        rewardAd = new RewardedAd(rewardId);

        //call events
        rewardAd.OnAdLoaded         += HandleRewardAdLoaded;
        rewardAd.OnAdFailedToLoad   += HandleRewardAdFailedToLoad;
        rewardAd.OnAdOpening        += HandleRewardAdOpening;
        rewardAd.OnAdFailedToShow   += HandleRewardAdFailedToShow;
        rewardAd.OnUserEarnedReward += HandleUserEarnedReward;
        rewardAd.OnAdClosed         += HandleRewardAdClosed;


        //create and ad request
        if (PlayerPrefs.HasKey("Consent"))
        {
            AdRequest request = new AdRequest.Builder().Build();
            rewardAd.LoadAd(request); //load & show the banner ad
        }
        else
        {
            AdRequest request = new AdRequest.Builder().AddExtra("npa", "1").Build();
            rewardAd.LoadAd(request); //load & show the banner ad (non-personalised)
        }
    }
示例#2
0
    public void LoadAdMobRV()
    {
        rewardedAd = new RewardedAd(admobRvAdUnitID);

        // Called when an ad request has successfully loaded.
        rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
        // Called when an ad request failed to load.
        rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
        // Called when an ad is shown.
        rewardedAd.OnAdOpening += HandleRewardedAdOpening;
        // Called when an ad request failed to show.
        rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
        // Called when the user should be rewarded for interacting with the ad.
        rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
        // Called when the ad is closed.
        rewardedAd.OnAdClosed += HandleRewardedAdClosed;

        if (ADXGDPRManager.GetConsentState() == 2)
        {
            AdRequest request = new AdRequest.Builder()
                                .AddExtra("npa", "1")
                                .Build();
            rewardedAd.LoadAd(request);
        }
        else
        {
            AdRequest request = new AdRequest.Builder().Build();
            rewardedAd.LoadAd(request);
        }
    }
        public void LoadRewardedVideo(string adUnit, AdMobRewardedOptions options = null)
        {
            if (!CrossAdMob.Current.IsEnabled)
            {
                return;
            }

            if (IsInTestMode || String.IsNullOrWhiteSpace(adUnit))
            {
                adUnit = GoogleSamplesAdUnitIds.AndroidSampleAdUnitId_RewardedVideo;
            }

            if (_rewardedVideoAds == null)
            {
                CreateRewardedVideo(adUnit);
            }

            if (!_rewardedVideoAds.IsLoaded)
            {
                //if (options != null)
                //{
                //    _rewardedVideoAds.UserId = options.UserId;
                //    _rewardedVideoAds.CustomData = options.CustomData;
                //}
                var loadCallback = new AdMobRewardedLoadCallback(adUnit);
                loadCallback.AdLoaded       += LoadCallback_AdLoaded;
                loadCallback.AdFailedToLoad += LoadCallback_AdFailedToLoad;

                _rewardedVideoAds.LoadAd(GetRequest(), loadCallback);
            }
            else
            {
                Console.WriteLine("RewardedVideo already loaded");
            }
        }
示例#4
0
    public void RequestAndLoadRewardedAd()
    {
        statusText.text = "Requesting Rewarded Ad.";
#if UNITY_EDITOR
        string adUnitId = "unused";
#elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-5134338854978158/6080808259";
#elif UNITY_IPHONE
        string adUnitId = "";
#else
        string adUnitId = "unexpected_platform";
#endif

        // create new rewarded ad instance
        rewardedAd = new RewardedAd(adUnitId);

        // Add Event Handlers
        rewardedAd.OnAdLoaded         += (sender, args) => OnAdLoadedEvent.Invoke();
        rewardedAd.OnAdFailedToLoad   += (sender, args) => OnAdFailedToLoadEvent.Invoke();
        rewardedAd.OnAdOpening        += (sender, args) => OnAdOpeningEvent.Invoke();
        rewardedAd.OnAdFailedToShow   += (sender, args) => OnAdFailedToShowEvent.Invoke();
        rewardedAd.OnAdClosed         += (sender, args) => OnAdClosedEvent.Invoke();
        rewardedAd.OnUserEarnedReward += (sender, args) => OnUserEarnedRewardEvent.Invoke();

        // Create empty ad request
        rewardedAd.LoadAd(CreateAdRequest());
    }
 private void Update()
 {
     if (game.ads)
     {
         if (Input.GetKeyDown(KeyCode.Escape))
         {
             rewardedAd.OnAdLoaded -= HandleRewardedAdLoaded;
             DontWaitAds();
         }
         if (showReward)
         {
             if (rewardedAd.IsLoaded())
             {
                 rewardedAd.Show();
                 rewardedAd                     = new RewardedAd(inGameRewarded);
                 rewardedAd.OnAdClosed         += HandleRewardedAdClosed;
                 rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
                 rewardedAd.OnAdLoaded         += HandleRewardedAdLoaded;
                 request = null;
                 request = new AdRequest.Builder().Build();
                 rewardedAd.LoadAd(request);
                 showReward = false;
             }
         }
     }
 }
    void Start()
    {
        playerHealth         = FindObjectOfType <PlayerHealth>();
        gameOverMenuBehavior = FindObjectOfType <GameOverMenuBehavior>();
        rewardedGoogleAd     = FindObjectOfType <RewardedGoogleAd>();
        levelLoader          = FindObjectOfType <LevelLoader>();
        floor = FindObjectOfType <Floor>();

        firstAd  = new RewardedAd(adUnitId);
        secondAd = new RewardedAd(adUnitId);

        // Called when the user should be rewarded for interacting with the ad.
        firstAd.OnUserEarnedReward  += HandleUserEarnedFirstReward;
        secondAd.OnUserEarnedReward += HandleUserEarnedSecondReward;
        // Called when the ad is closed.
        firstAd.OnAdClosed  += HandleFirstRewardedAdClosed;
        secondAd.OnAdClosed += HandleSecondRewardedAdClosed;
        // Called when an ad request failed to load.
        firstAd.OnAdFailedToLoad  += HandleFirstRewardedAdFailedToLoad;
        secondAd.OnAdFailedToLoad += HandleSecondRewardedAdFailedToLoad;
        // Called when an ad request failed to show.
        firstAd.OnAdFailedToShow  += HandleFirstRewardedAdFailedToShow;
        secondAd.OnAdFailedToShow += HandleSecondRewardedAdFailedToShow;

        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();

        // Load the rewarded ad with the request.
        firstAd.LoadAd(request);
        secondAd.LoadAd(request);
    }
示例#7
0
    public RewardedAd CreateAndLoadRewardedAd(string placement)
    {
        var rewardedAd = new RewardedAd(placement);

        // Called when an ad request has successfully loaded.
        rewardedAd.OnAdLoaded += OnAdLoaded;
        // Called when an ad request failed to load.
        rewardedAd.OnAdFailedToLoad += OnAdFailedToLoad;
        // Called when an ad is shown.
        rewardedAd.OnAdOpening += OnAdOpening;
        // Called when an ad request failed to show.
        rewardedAd.OnAdFailedToShow += OnAdFailedToShow;
        // Called when the user should be rewarded for interacting with the ad.
        rewardedAd.OnUserEarnedReward += OnUserEarnedReward;
        // Called when the ad is closed.
        rewardedAd.OnAdClosed += OnAdClosed;

        if (rewardAdDict.ContainsKey(placement))
        {
            rewardAdDict[placement] = rewardedAd;
        }
        else
        {
            rewardAdDict.Add(placement, rewardedAd);
        }

        AdRequest request = new AdRequest.Builder().Build();

        rewardedAd.LoadAd(request);
        return(rewardedAd);
    }
示例#8
0
文件: GoogleAd.cs 项目: JanHwa/Unity
    // 激励广告(视频类)
    private void RequestRewarded()
    {
#if UNITY_ANDROID
        string adUnitId = reward_adID_AND;
#elif UNITY_IPHONE
        string adUnitId = reward_adID_iOS;
#else
        string adUnitId = "unexpected_platform";
#endif

        rewardedAd = new RewardedAd(adUnitId);
        // Create an empty ad request.

        AdRequest request;

        if (isDebug)
        {
            // FOR TESTING
            request = new AdRequest.Builder().AddTestDevice("2077ef9a63d2b398840261c8221a0c9b").Build();
        }
        else
        {
            // FOR REAL APP
            request = new AdRequest.Builder().Build();
        }

        // Load the interstitial with the request.
        rewardedAd.LoadAd(request);
        this.HandleRewardedEvents(true);
    }
        public void RequestRewardBasedVideo()
        {
            if (_rewardBasedVideo != null)
            {
                return;
            }

            // Create new rewarded ad instance.
            _rewardBasedVideo = new RewardedAd(_videoId);

            // Called when an ad request has successfully loaded.
            _rewardBasedVideo.OnAdLoaded += HandleRewardedAdLoaded;
            // Called when an ad request failed to load.
            _rewardBasedVideo.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
            // Called when an ad is shown.
            _rewardBasedVideo.OnAdOpening += HandleRewardedAdOpening;
            // Called when an ad request failed to show.
            _rewardBasedVideo.OnAdFailedToShow += HandleRewardedAdFailedToShow;
            // Called when the user should be rewarded for interacting with the ad.
            _rewardBasedVideo.OnUserEarnedReward += HandleUserEarnedReward;
            // Called when the ad is closed.
            _rewardBasedVideo.OnAdClosed += HandleRewardedAdClosed;

            // Create an empty ad request.
            var request = CreateAdRequest();

            // Load the rewarded ad with the request.
            _rewardBasedVideo.LoadAd(request);
        }
示例#10
0
        public void CreateAndLoadRewardedAd()
        {
#if UNITY_ANDROID
            string adUnitId = "ca-app-pub-3375705566833853/7623702329";
#else
            string adUnitId = "ca-app-pub-3940256099942544/5224354917";
#endif
            _rewardedAd = new RewardedAd(adUnitId);

            _rewardedAd.OnUserEarnedReward +=
                (object sender, Reward args) =>
            {
                _rewardedAdEarned.Push(_rewardAction);
                //CreateAndLoadRewardedAd();
            };

            _rewardedAd.OnAdClosed +=
                (object sender, EventArgs args) =>
            {
                CreateAndLoadRewardedAd();
            };

            AdRequest request = new AdRequest.Builder().Build();
            _rewardedAd.LoadAd(request);
        }
示例#11
0
    void SetupRewardedAds()
    {
        if (rewardedAd == null)
        {
            RewardVideoLoading = true;
            rewardedAd         = new RewardedAd(rewardedAdID);

            rewardedAd.OnAdLoaded         += HandleRewardBasedVideoLoaded;
            rewardedAd.OnAdFailedToLoad   += HandleRewardBasedVideoFailedToLoad;
            rewardedAd.OnUserEarnedReward += HandleRewardBasedVideoRewarded;
            rewardedAd.OnAdClosed         += HandleRewardBasedVideoClosed;
            AdRequest request = new AdRequest.Builder().Build();
            rewardedAd.LoadAd(request);
        }
        else
        {
            StartCoroutine(CheckInternetConnection((isConnected) =>
            {
                if (isConnected && !rewardedAd.IsLoaded())
                {
                    RewardVideoLoading = true;
                    rewardedAd         = new RewardedAd(rewardedAdID);

                    rewardedAd.OnAdLoaded         += HandleRewardBasedVideoLoaded;
                    rewardedAd.OnAdFailedToLoad   += HandleRewardBasedVideoFailedToLoad;
                    rewardedAd.OnUserEarnedReward += HandleRewardBasedVideoRewarded;
                    rewardedAd.OnAdClosed         += HandleRewardBasedVideoClosed;
                    AdRequest request              = new AdRequest.Builder().Build();
                    rewardedAd.LoadAd(request);
                }
            }));
        }
    }
示例#12
0
        /// <summary>
        /// Loads an Admob rewarded video
        /// </summary>
        private void LoadRewardedVideo()
        {
            if (debug)
            {
                Debug.Log("Admob Start Loading Rewarded Video");
                ScreenWriter.Write("Admob Start Loading Rewarded Video");
            }
            if (rewardedVideo != null)
            {
                rewardedVideo.OnAdLoaded         -= RewardedVideoLoaded;
                rewardedVideo.OnUserEarnedReward -= RewardedVideoWatched;
                rewardedVideo.OnAdFailedToLoad   -= RewardedVideoFailed;
                rewardedVideo.OnAdClosed         -= OnAdClosed;
                rewardedVideo.OnAdOpening        -= OnAdOpening;
                rewardedVideo.OnAdFailedToShow   -= OnAdFailedToShow;
            }


            rewardedVideo                     = new RewardedAd(rewardedVideoId);
            rewardedVideo.OnAdLoaded         += RewardedVideoLoaded;
            rewardedVideo.OnUserEarnedReward += RewardedVideoWatched;
            rewardedVideo.OnAdFailedToLoad   += RewardedVideoFailed;
            rewardedVideo.OnAdClosed         += OnAdClosed;
            rewardedVideo.OnAdOpening        += OnAdOpening;
            rewardedVideo.OnAdFailedToShow   += OnAdFailedToShow;

            AdRequest request = new AdRequest.Builder().AddExtra("npa", consent).AddExtra("is_designed_for_families", designedForFamilies).TagForChildDirectedTreatment(directedForChildren).AddExtra("rdp", ccpaConsent).Build();

            rewardedVideo.LoadAd(request);
        }
示例#13
0
    private void CreateAndLoadAd()
    {
        // ca-app-pub-3940256099942544/5224354917   testing
        // ca - app - pub - 3940256099942544 / 5224354917   own
        m_AdUnit = "ca-app-pub-3940256099942544/5224354917";

        m_RewardedAd = new RewardedAd(m_AdUnit);

        // Called when an ad request has successfully loaded.
        m_RewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
        // Called when an ad request failed to load.
        m_RewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
        // Called when an ad is shown.
        m_RewardedAd.OnAdOpening += HandleRewardedAdOpening;
        // Called when an ad request failed to show.
        m_RewardedAd.OnAdFailedToShow   += HandleRewardedAdFailedToShow;
        m_RewardedAd.OnUserEarnedReward += HandleUserReward;
        m_RewardedAd.OnAdClosed         += HandleCoinAdClosed;

        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();

        // Load the rewarded ad with the request.
        m_RewardedAd.LoadAd(request);
    }
        public void LoadTimeUpRewardAds(string adsId)
        {
            _timeUpRewardAd             = new RewardedAd(adsId);
            _timeUpRewardAd.OnAdLoaded += (sender, e) =>
            {
                Callback?.OnTimeUpRewardLoaded();
            };
            _timeUpRewardAd.OnAdFailedToLoad += (sender, e) => {
                LoadTimeUpRewardAds(adsId);
                Callback?.OnTimeUpRewardFailedToLoad();
            };
            _timeUpRewardAd.OnAdOpening += (sender, e) => {
                _isTimeUpRewardShow = true;
                Callback?.OnTimeUpRewardShow();
            };
            _timeUpRewardAd.OnAdClosed += (sender, e) => {
                _isTimeUpRewardShow = false;
                LoadTimeUpRewardAds(adsId);
                Callback?.OnTimeUpRewardDismiss();
            };
            _timeUpRewardAd.OnUserEarnedReward += (sender, e) =>
            {
                Callback?.OnTimeUpRewardDidReward();
            };
            AdRequest request = new AdRequest.Builder().Build();

            _timeUpRewardAd.LoadAd(request);
        }
示例#15
0
    public void LoadVideo()
    {
        //string adUnitId = "ca-app-pub-3940256099942544/5224354917";
        //live add below
        string adUnitId = "ca-app-pub-8604801943822079/1090730324";

        rewardedAd = new RewardedAd(adUnitId);

        this.rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
        // Called when an ad request failed to load.
        this.rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
        // Called when an ad is shown.
        this.rewardedAd.OnAdOpening += HandleRewardedAdOpening;
        // Called when an ad request failed to show.
        this.rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
        // Called when the user should be rewarded for interacting with the ad.
        this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
        // Called when the ad is closed.
        this.rewardedAd.OnAdClosed += HandleRewardedAdClosed;


        AdRequest request = new AdRequest.Builder().Build();

        rewardedAd.LoadAd(request);
    }
示例#16
0
    void Ad()
    {
        rewardedAd = new RewardedAd("ca-app-pub-3940256099942544/5224354917");
        AdRequest request = new AdRequest.Builder().Build();

        rewardedAd.LoadAd(request);

        rewardedAd.OnAdLoaded       += HandleRewardedAdLoaded;
        rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
        rewardedAd.OnAdOpening      += HandleRewardedAdOpening;
        rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
        rewardedAd.OnAdClosed       += HandleRewardedAdClosed;

        rewardedAd.OnUserEarnedReward += (o, e) =>
        {
            PersonEng.HP = 50;
            Person.GetComponent <PersonEng>().enabled = true;
            Person.GetComponent <PersonEng>().EnablePerson(true);
            gameObject.SetActive(false);
        };

        ButtonYes.GetComponent <Button>().onClick.AddListener(() =>
        {
            show = true;
            WaitWindow(false);
        });

        ButtonNo.GetComponent <Button>().onClick.AddListener(() =>
        {
            Person.GetComponent <PersonEng>().EnablePerson(true);
            Scene mainScene = SceneManager.GetActiveScene();
            SceneManager.LoadScene(0);
        });
    }
        /// <summary>
        /// Load a rewarded ad.
        /// </summary>
        public void LoadRewardedAd(string adUnitId = null, Action onLoadedCallback = null, Action onFailedToLoadCallback = null)
        {
            if (adUnitId == null)
            {
#if UNITY_ANDROID
                adUnitId = PlayerPrefs.GetString("MyAdMobManager_RewardedAdId", mAndroidDefaultRewardedAdId);
#elif UNITY_IOS
                adUnitId = PlayerPrefs.GetString("MyAdMobManager_RewardedAdId", mIosDefaultRewardedAdId);
#endif
            }

#if DEBUG_MY_ADMOB
            Debug.Log("[" + typeof(MyAdMobManager).Name + "] LoadRewardedAd(): adUnitId=" + adUnitId);
#endif

            mOnRewardedAdLoadedCallback       = onLoadedCallback;
            mOnRewardedAdFailedToLoadCallback = onFailedToLoadCallback;

            mIsLoadingRewardred = true;

            mRewardedAd = new RewardedAd(adUnitId);
            mRewardedAd.LoadAd(new AdRequest.Builder().Build());
            mRewardedAd.OnAdLoaded         += _OnRewardedAdLoaded;
            mRewardedAd.OnAdFailedToLoad   += _OnRewardedAdFaiedToLoad;
            mRewardedAd.OnAdOpening        += _OnRewardedAdOpening;
            mRewardedAd.OnAdFailedToShow   += _OnRewardedAdFaiedToShow;
            mRewardedAd.OnUserEarnedReward += _OnRewardedAdUserEarnedReward;
            mRewardedAd.OnAdClosed         += _OnRewardedAdClosed;
        }
示例#18
0
        /// <summary>
        /// Request for load ad
        /// </summary>
        private void Request()
        {
            var builder = new AdRequest.Builder();

            if (IsTest)
            {
                builder
                .AddTestDevice(AdRequest.TestDeviceSimulator)
                .AddTestDevice(UniqueID);
            }

            var adRequest = builder.Build();

            switch (AdType)
            {
            case AdType.RewardVideoAd:
                rewardedAd.LoadAd(adRequest);
                break;

            case AdType.BannerView:
                bannerView.LoadAd(adRequest);
                break;

            case AdType.InterstitialAd:
                interstitialAd.LoadAd(adRequest);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#19
0
    public static void RequestReward()
    {
        string id = "ca-app-pub-3940256099942544/5224354917";

        //string id = "ca-app-pub-3181861234105818/3965464230";
        reward = new RewardedAd(id);

        // Called when an ad request has successfully loaded.
        reward.OnAdLoaded += HandleRewardedAdLoaded;
        // Called when an ad request failed to load.
        reward.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
        // Called when an ad is shown.
        reward.OnAdOpening += HandleRewardedAdOpening;
        // Called when an ad request failed to show.
        reward.OnAdFailedToShow += HandleRewardedAdFailedToShow;
        // Called when the user should be rewarded for interacting with the ad.
        reward.OnUserEarnedReward += HandleUserEarnedReward;
        // Called when the ad is closed.
        reward.OnAdClosed += HandleRewardedAdClosed;

        AdRequest request = new AdRequest.Builder().
                            AddTestDevice("ca-app-pub-3940256099942544/6300978111"). //remove when done testing
                            Build();

        reward.LoadAd(request);
    }
示例#20
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;
        }
    public void RequestAndLoadRewardedAd()
    {
        Debug.Log("Requesting Rewarded Ad.");
#if UNITY_EDITOR
        string adUnitId = "unused";
#elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-3940256099942544/1712485313";
#else
        string adUnitId = "unexpected_platform";
#endif

        // create new rewarded ad instance
        rewardedAd = new RewardedAd(adUnitId);

        // Add Event Handlers
        rewardedAd.OnAdLoaded         += (sender, args) => OnAdLoadedEvent.Invoke();
        rewardedAd.OnAdFailedToLoad   += (sender, args) => OnAdFailedToLoadEvent.Invoke();
        rewardedAd.OnAdOpening        += (sender, args) => OnAdOpeningEvent.Invoke();
        rewardedAd.OnAdFailedToShow   += (sender, args) => OnAdFailedToShowEvent.Invoke();
        rewardedAd.OnAdClosed         += (sender, args) => OnAdClosedEvent.Invoke();
        rewardedAd.OnUserEarnedReward += (sender, args) => OnUserEarnedRewardEvent.Invoke();

        // Create empty ad request
        rewardedAd.LoadAd(CreateAdRequest());
    }
示例#22
0
        /// <summary>
        /// Method of load ad. This method is async
        /// </summary>
        public async void Load()
        {
#if UNITY_ANDROID
            bannerBottom    = new BannerView(androidBannerID, AdSize.Banner, AdPosition.Bottom);
            imageAd         = new InterstitialAd(androidImageID);
            videoAd         = new InterstitialAd(androidVideoID);
            rewardedVideoAd = new RewardedAd(androidRewardVideoID);
#elif UNITY_IPHONE
            bannerBottom    = new BannerView(iosBannerID, AdSize.Banner, AdPosition.Bottom);
            imageAd         = new InterstitialAd(iosImageID);
            videoAd         = new InterstitialAd(iosVideoID);
            rewardedVideoAd = new RewardedAd(iosRewardVideoID);
#else
            Debug.LogError("Platform not support!");
            return;
#endif
            AdRequest request = new AdRequest.Builder().Build();

            await Task.Run(() => bannerBottom.LoadAd(request));

            await Task.Run(() => imageAd.LoadAd(request));

            await Task.Run(() => videoAd.LoadAd(request));

            await Task.Run(() => rewardedVideoAd.LoadAd(request));

            AddEvents();
        }
示例#23
0
    public void RequestRewardAd()
    {
        string adUnitID;

#if UNITY_ANDROID
        adUnitID = reward_ADR_ID;
#elif UNITY_IPHONE
        adUnitID = reward_IOS_ID;
#endif

        rewardedAd = new RewardedAd(adUnitID);

        // Called when an ad request has successfully loaded.
        rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
        // Called when an ad request failed to load.
        rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
        // Called when an ad is shown.
        rewardedAd.OnAdOpening += HandleRewardedAdOpening;
        // Called when an ad request failed to show.
        rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
        // Called when the user should be rewarded for interacting with the ad.
        rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
        // Called when the ad is closed.
        rewardedAd.OnAdClosed += HandleRewardedAdClosed;

        AdRequest request = new AdRequest.Builder().Build();
        rewardedAd.LoadAd(request);
    }
示例#24
0
        public void TryPlayRewardedAd()
        {
            if (CheckInternetConnection())
            {
                return;
            }

            string adId;

            var isDebugBuild = Debug.isDebugBuild;

            if (isDebugBuild)
            {
                adId = Constants.AdMob.TestAd;
            }
            else
            {
                adId = Constants.AdMob.Reward;
            }

            RewardedAd rewardedAd = new RewardedAd(adId);

            var adRequest = new AdRequest.Builder().Build();

            rewardedAd.LoadAd(adRequest);

            rewardedAd.Show();
            rewardedAd.OnAdClosed += OnAdClosed;
        }
示例#25
0
    public void CreateAndLoadRewardedAd(string adId, IRewardedAdListener listener)
    {
        var rewardedAd = new RewardedAd(adId);

        rewardedAd.OnAdLoaded += (sender, args) =>
        {
            listener.OnAdLoaded(adId);
        };
        rewardedAd.OnUserEarnedReward += (sender, reward) =>
        {
            listener.OnRewardEarned(adId);
        };
        rewardedAd.OnAdFailedToLoad += (sender, args) =>
        {
            Debug.Log("rewardedAd.OnAdFailedToLoad - " + args.Message);
            listener.OnAdLoadFailed(adId);
        };
        rewardedAd.OnAdClosed += (sender, args) =>
        {
            listener.OnAdClosed(adId);
        };

        rewardedAd.LoadAd(CreateAdRequest());

        if (_rewardedAds.ContainsKey(adId))
        {
            _rewardedAds.Remove(adId);
        }
        _rewardedAds.Add(adId, rewardedAd);
    }
 private void Update()
 {
     if (interactableButtons == false)
     {
         buttonResurrect.interactable      = false;
         buttonResurrectClose.interactable = false;
     }
     if (Input.GetKeyDown(KeyCode.Escape) && openAds.activeSelf == true)
     {
         rewardedAd.OnAdLoaded -= HandleRewardedAdLoaded;
         DontWaitAds();
     }
     else if (Input.GetKeyDown(KeyCode.Escape) && openAds.activeSelf == false)
     {
         ButtonResurrectClose();
     }
     if (showReward)
     {
         if (rewardedAd.IsLoaded())
         {
             rewardedAd.Show();
             rewardedAd                     = new RewardedAd(inGameRewarded);
             rewardedAd.OnAdClosed         += HandleRewardedAdClosed;
             rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
             rewardedAd.OnAdLoaded         += HandleRewardedAdLoaded;
             request = null;
             request = new AdRequest.Builder().Build();
             rewardedAd.LoadAd(request);
             showReward = false;
         }
     }
 }
示例#27
0
文件: AdsManager.cs 项目: Oxann/Dots
    private void RequestRewardedVideoAd()
    {
        rewardedVideo = new RewardedAd(Rewarded_Video_ID);
        AdRequest request = new AdRequest.Builder().Build();

        rewardedVideo.LoadAd(request);
    }
    public override void Init()
    {
        if (!IsInit)
        {
            IsInit = true;

            rewardedAd = new RewardedAd(UnitId);

            // Called when an ad request has successfully loaded.
            rewardedAd.OnAdLoaded += HandleOnAdLoaded;
            // Called when an ad request failed to load.
            rewardedAd.OnAdFailedToLoad += HandleRewardBasedVideoFailedToLoad;
            // Called when an ad is shown.
            rewardedAd.OnAdOpening += HandleRewardBasedVideoStarted;
            // Called when an ad request failed to show.
            rewardedAd.OnAdFailedToShow += HandleRewardBasedVideoFailedToShow;
            // Called when the user should be rewarded for interacting with the ad.
            rewardedAd.OnUserEarnedReward += HandleRewardBasedVideoRewarded;
            // Called when the ad is closed.
            rewardedAd.OnAdClosed += HandleOnAdClosed;
        }

        // Create an empty ad request.
        var builder = new AdRequest.Builder();
        var request = builder.Build();

        // Load the banner with the request.
        rewardedAd.LoadAd(request);
    }
示例#29
0
    public RewardedAd CreateAndLoadRewardedAd(string adUnitId)
    {
        RewardedAd rewardedAd = new RewardedAd(adUnitId);

        // Called when an ad request has successfully loaded.
        rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
        // Called when an ad request failed to load.
        rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
        // Called when an ad is shown.
        rewardedAd.OnAdOpening += HandleRewardedAdOpening;
        // Called when an ad request failed to show.
        rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
        // Called when the user should be rewarded for interacting with the ad.
        rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
        // Called when the ad is closed.
        rewardedAd.OnAdClosed += HandleRewardedAdClosed;

        // Create an empty ad request.
        AdRequest request = new AdRequest.Builder().Build();

        // Load the rewarded ad with the request.
        rewardedAd.LoadAd(request);

        return(rewardedAd);
    }
示例#30
0
 public void RequestRewardAd()
 {
     AdReward             = new RewardedAd(idReward);
     AdReward.OnAdClosed += (sender, e) => {
         if (OnRewardAdClosed != null)
         {
             OnRewardAdClosed.Invoke();
         }
     };
     AdReward.OnAdOpening += (sender, e) => {
         if (OnRewardAdOpening != null)
         {
             OnRewardAdOpening.Invoke();
         }
     };
     AdReward.OnAdFailedToLoad += (sender, e) => {
         if (OnRewardAdFailedToLoad != null)
         {
             OnRewardAdFailedToLoad.Invoke();
         }
     };
     AdReward.OnAdLoaded += (sender, e) => {
         if (OnRewardAdLoaded != null)
         {
             OnRewardAdLoaded.Invoke();
         }
     };
     AdReward.OnUserEarnedReward += (sender, reward) => {
         if (OnRewardAdWatched != null)
         {
             OnRewardAdWatched.Invoke(reward);
         }
     };
     AdReward.LoadAd(CreateAdRequest());
 }