Beispiel #1
0
        private IEnumerator _ShowRewardVideoAdAsync(OnFinishRewardVideo onFinish)
        {
            var adList = new List <IVideoAdvertisement>();

            adList.AddRange(this._ads);
            if (randomize)
            {
                adList.Shuffle();
            }

            bool          finish;
            VideoAdStatus status = VideoAdStatus.AdNotReadyOrShowing;

            foreach (var v in adList)
            {
                finish = false;
                StartCoroutine(v.ShowRewardVideoAsync((s) =>
                {
                    finish = true;
                    status = s;
                }));
                yield return(new WaitUntil(() => finish));

                if (status != VideoAdStatus.AdNotReadyOrShowing)
                {
                    onFinish.Invoke(status);
                    yield break;
                }
            }

            onFinish.Invoke(VideoAdStatus.Fail);
        }
Beispiel #2
0
        public IEnumerator ShowRewardVideoAsync(OnFinishRewardVideo onFinish)
        {
            if (Advertisement.GetPlacementState(this.placementId) == PlacementState.Waiting)
            {
                // 1秒くらい待ってみる.
                int count = 0;
                while (count < 10 && !Advertisement.IsReady(this.placementId))
                {
                    yield return(new WaitForSecondsRealtime(0.1f));

                    count++;
                }

                if (Advertisement.IsReady(this.placementId))
                {
                }
                else
                {
                    onFinish.Invoke(VideoAdStatus.AdNotReadyOrShowing);
                    yield break;
                }
            }

            // 表示中の際はfalseで返す.
            if (Advertisement.isShowing)
            {
                onFinish.Invoke(VideoAdStatus.AdNotReadyOrShowing);
                yield break;
            }
            this.onFinish = onFinish;
            ShowAd(onFinish);
        }
Beispiel #3
0
        public bool ShowRewardVideoAd(OnFinishRewardVideo onFinish)
        {
            if (!Advertisement.isSupported)
            {
                return(false);
            }

            if (!Advertisement.isInitialized)
            {
                return(false);
            }

            if (!Advertisement.IsReady(this.placementId))
            {
                return(false);
            }

#if !UNITY_EDITOR
            // Editor上では表示してないのにtrueが返るような...
            if (!Advertisement.isShowing)
            {
                return(false);
            }
#endif
            Advertisement.Show(this.placementId, new ShowOptions()
            {
                resultCallback = (v) =>
                {
                    VideoAdStatus status = VideoAdStatus.Fail;
                    switch (v)
                    {
                    case ShowResult.Failed:
                        status = VideoAdStatus.Fail;
                        break;

                    case ShowResult.Skipped:
                        status = VideoAdStatus.Cancel;
                        break;

                    case ShowResult.Finished:
                        status = VideoAdStatus.Success;
                        break;
                    }
                    onFinish.Invoke(status);
                }
            });

            return(true);
        }
Beispiel #4
0
        public void OnUnityAdsDidFinish(string placementId, UnityEngine.Advertisements.ShowResult showResult)
        {
            VideoAdStatus status = VideoAdStatus.Cancel;

            switch (showResult)
            {
            case ShowResult.Failed:
                status = VideoAdStatus.Fail;
                break;

            case ShowResult.Skipped:
                status = VideoAdStatus.Cancel;
                break;

            case ShowResult.Finished:
            default:
                status = VideoAdStatus.Success;
                break;
            }

            onFinish.Invoke(status);
        }
Beispiel #5
0
 public void OnClickClose()
 {
     onFinish.Invoke(VideoAdStatus.Cancel);
     Destroy(gameObject);
 }