Пример #1
0
 public void PlayAds(string placementID)
 {
     if (Advertisement.IsReady(placementID))
     {
         if (Advertisement.GetPlacementState() == PlacementState.Ready)
         {
             ShowOptions options = new ShowOptions();
             options.resultCallback = this.HandleCallback;
             Advertisement.Show(placementID, options);
         }
         else if (Advertisement.GetPlacementState() == PlacementState.Disabled)
         {
             if (PlayFailed != null)
             {
                 PlayFailed(EAdsPlayFailedReason.NotSupport);
             }
         }
         else
         {
             if (PlayFailed != null)
             {
                 PlayFailed(EAdsPlayFailedReason.NotReady);
             }
         }
     }
     else
     {
         if (PlayFailed != null)
         {
             PlayFailed(EAdsPlayFailedReason.NotReady);
         }
     }
 }
Пример #2
0
    IEnumerator CoRequestInterstitial(string placementId, AdsManager.InterstitialDelegate onAdLoaded = null, bool showLoading = true)
    {
        float                  _timeoutRequestAds = timeoutRequestAds;
        PlacementState         adState            = PlacementState.Waiting;
        float                  retryInterval      = 0.4f;
        WaitForSecondsRealtime delay = new WaitForSecondsRealtime(retryInterval);
        int tryTimes = 0;

        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            Debug.Log("unity ad not reachable " + Application.internetReachability);
            _timeoutRequestAds = 3f;
        }
        while (adState != PlacementState.Ready && tryTimes < _timeoutRequestAds / retryInterval)
        {
            adState = Advertisement.GetPlacementState(placementId);
            if (adState != PlacementState.Ready)
            {
                yield return(delay);

                tryTimes++;
            }
        }
        Debug.Log("Unity request ad state " + adState);
        onAdLoaded?.Invoke(adState == PlacementState.Ready);
        //if (showLoading)
        //    Manager.LoadingAnimation(false);
    }
Пример #3
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);
        }
Пример #4
0
 // Implement IUnityAdsListener interface methods:
 public void OnUnityAdsDidFinish(string placementId, UnityEngine.Advertisements.ShowResult showResult)
 {
     if (!string.IsNullOrEmpty(currentRewardId) && string.Equals(currentRewardId, placementId))
     {
         // Define conditional logic for each ad completion status:
         if (showResult == UnityEngine.Advertisements.ShowResult.Finished)
         {
             onRewardWatched?.Invoke(new RewardResult(RewardResult.Type.Finished));
             // Reward the user for watching the ad to completion.
         }
         else if (showResult == UnityEngine.Advertisements.ShowResult.Skipped)
         {
             onRewardWatched?.Invoke(new RewardResult(RewardResult.Type.Canceled));
             Debug.Log("skipped ad");
             // Do not reward the user for skipping the ad.
         }
         else if (showResult == UnityEngine.Advertisements.ShowResult.Failed)
         {
             onRewardWatched?.Invoke(new RewardResult(RewardResult.Type.LoadFailed));
             AdsManager.ShowError(Advertisement.GetPlacementState(currentRewardId).ToString(), placementId);
             Debug.LogWarning("The ad did not finish due to an error.");
         }
         onRewardWatched = null;
     }
     else if (onInterstitialClosed != null) //closing a interstitial ads
     {
         onInterstitialClosed.Invoke(showResult == UnityEngine.Advertisements.ShowResult.Finished);
         onInterstitialClosed = null;
     }
 }
Пример #5
0
    public void ShowAds()
    {
#if UNITY_ADS
        if (Advertisement.IsReady(adsPlacementId))
        {
#if UNITY_ANALYTICS
            AnalyticsEvent.AdStart(adsRewarded, adsNetwork, adsPlacementId, new Dictionary <string, object>
            {
                { "level_index", PlayerData.instance.rank },
                { "distance", TrackManager.instance == null ? 0 : TrackManager.instance.worldDistance },
            });
#endif
            var options = new ShowOptions {
                resultCallback = HandleShowResult
            };
            Advertisement.Show(adsPlacementId, options);
        }
        else
        {
#if UNITY_ANALYTICS
            AnalyticsEvent.AdSkip(adsRewarded, adsNetwork, adsPlacementId, new Dictionary <string, object> {
                { "error", Advertisement.GetPlacementState(adsPlacementId).ToString() }
            });
#endif
        }
#endif
    }
Пример #6
0
    public void ShowAd()
    {
        if (!Advertisement.IsReady())
        {
            Debug.LogWarning("動画広告の準備が出来ていません");
            return;
        }

        var state = Advertisement.GetPlacementState(VIDEO_PLACEMENT_ID);

        if (state != PlacementState.Ready)
        {
            Debug.LogWarning($"{VIDEO_PLACEMENT_ID}の準備が出来ていません。現在の状態 : {state}");
            return;
        }

        //Ads準備完了時
        if (Advertisement.IsReady())
        {
            if (adIsReady == true)
            {
                Advertisement.Show();
                pointDisplay.AddPoint();
                lastDateTime = DateTime.UtcNow;
                adIsReady    = false;
                timeTextObject.SetActive(true);
                pointText.SetActive(false);
                adsButtonImage.color = new Color(255, 255, 255, 0.5f);
            }
        }
    }
Пример #7
0
    void Awake()
    {
        Advertisement.Initialize(gameID, true);

        Debug.Log("Unity Ads initialized: " + Advertisement.isInitialized);
        Debug.Log("Unity Ads is supported: " + Advertisement.isSupported);
        Debug.Log("Unity Ads test mode enabled: " + Advertisement.testMode);
        Debug.Log("Unity Ads game id: " + Advertisement.gameId);
        Debug.Log("Unity Ads is ready: " + Advertisement.IsReady(null));
        Debug.Log("Unity Ads placement state: " + Advertisement.GetPlacementState(placementID));
    }
Пример #8
0
 public bool UnityAdsIsReady(string placement)
 {
     if (Advertisement.isInitialized && Advertisement.IsReady(placement))
     {
         return(true);
     }
     else
     {
         Debug.Log(Advertisement.GetPlacementState());
         return(false);
     }
 }
Пример #9
0
    public bool UnityAdsIsDefaultPlacementReady()
    {
//		Debug.Log ("Ad ready");
        if (Advertisement.isInitialized && Advertisement.IsReady())
        {
            return(true);
        }
        else
        {
            Debug.Log(Advertisement.GetPlacementState());
            return(false);
        }
    }
Пример #10
0
    IEnumerator ShowBannerWhenReady(string placementId, BannerPosition bannerPosition, AdsManager.InterstitialDelegate onAdLoaded = null)
    {
        Advertisement.Banner.SetPosition(bannerPosition);

        BannerLoadOptions options = new BannerLoadOptions {
            loadCallback = OnLoadBannerSuccess, errorCallback = OnLoadBannerFail
        };

        Advertisement.Banner.Load(placementId, options);

        float timeoutTime = 5f, retryInterval = 0.2f;
        WaitForSecondsRealtime delay = new WaitForSecondsRealtime(retryInterval);
        int tryTimes = 0;

        while (!bannerLoadSuccess.HasValue && tryTimes < timeoutTime / retryInterval)
        {
            yield return(delay);

            tryTimes++;
        }

        if (!bannerLoadSuccess.HasValue)
        {
            LogEvent("LoadBannerTimeout", "", "");
            bannerLoadSuccess = false;
        }
        onAdLoaded?.Invoke(bannerLoadSuccess.Value);

        bool           adReady = Advertisement.IsReady(placementId);
        PlacementState adState = Advertisement.GetPlacementState(placementId);

        if (bannerLoadSuccess.Value)
        {
            Debug.Log($"Unity banner showing. State: {Advertisement.GetPlacementState(placementId)}, ready {adReady}");
            Advertisement.Banner.Show(placementId);
        }
        else
        {
            Debug.Log($"Unity banner show failed. State: {Advertisement.GetPlacementState(placementId)}, ready {adReady}");
        }

        /*if (adReady) //show banner regardless of load success or not since Unity Ads is the only ads
         *  Advertisement.Banner.Show(placementId);*/
        bannerLoadSuccess = null;
    }
Пример #11
0
 public void Show(string type = "rewardedVideo")
 {
     Start();
     if (Advertisement.GetPlacementState() == PlacementState.Ready)
     {
         if (Advertisement.IsReady() && type == "rewardedVideo")
         {
             Advertisement.Show("rewardedVideo");
         }
         else if ((Advertisement.IsReady() && type == "video"))
         {
             Advertisement.Show("video");
         }
     }
     else
     {
         // hmmmmm
     }
 }
Пример #12
0
    /**
     * Advertisementクラスを使って動画広告を表示する
     */
    public void ShowAds()
    {
        // 指定のplacementが準備完了であるかどうかを確かめる
        // 簡易チェックでよければこれでOK
        //if (Advertisement.IsReady(placementId) == false) return;

        // 指定のplacementがどのような状態にあるかを調べる
        var placementState = Advertisement.GetPlacementState(placementId);

        switch (placementState)
        {
        case PlacementState.Ready:
            // 広告が表示できる状態のとき
            Debug.Log($"placement id: {placementId} Ready");
            break;

        case PlacementState.NotAvailable:
            // 広告枠が存在しないとき placement idを間違えている場合はここ
            Debug.Log($"placement id: {placementId} Not Available");
            return;

        case PlacementState.Disabled:
            // 広告枠が無効化されているとき
            Debug.Log($"placement id: {placementId} Disabled");
            return;

        case PlacementState.NoFill:
            // 広告在庫切れのとき
            Debug.Log($"placement id: {placementId} No Fill");
            break;

        case PlacementState.Waiting:
            // 次の広告の準備中
            Debug.Log($"placement id: {placementId} Waiting");
            return;

        default:
            throw new ArgumentOutOfRangeException();
        }

        // 広告を表示
        Advertisement.Show(placementId);
    }
Пример #13
0
    void Start()
    {
        Advertisement.AddListener(this);
        Advertisement.Initialize(gameId, testMode);

        var stateBanner = Advertisement.GetPlacementState(bannerId);
        var stateReward = Advertisement.GetPlacementState(rewardId);
        var stateVideo  = Advertisement.GetPlacementState(videoId);

        if (stateBanner == PlacementState.Ready)
        {
            OnUnityAdsReady(bannerId);
        }
        if (stateReward == PlacementState.Ready)
        {
            OnUnityAdsReady(rewardId);
        }
        if (stateVideo == PlacementState.Ready)
        {
            OnUnityAdsReady(videoId);
        }
    }
Пример #14
0
    IEnumerator LoadBanner()
    {
        Debug.Log("Clicked LoadBanner");
        while (!Advertisement.IsReady("banner"))
        {
            Debug.Log("Banner is not ready with state: " + Advertisement.GetPlacementState("banner"));
            yield return(new WaitForSeconds(0.5f));
        }

        if (Advertisement.IsReady("banner"))
        {
            Debug.Log("Load banner");
            BannerLoadOptions bannerLoadOptions = new BannerLoadOptions();
            bannerLoadOptions.loadCallback  = BannerLoadCallback;
            bannerLoadOptions.errorCallback = BannerErrorCallback;
            Advertisement.Banner.Load("banner", bannerLoadOptions);
        }
        else
        {
            Debug.Log("Banner is not ready with state: " + Advertisement.GetPlacementState("banner"));
        }
    }
Пример #15
0
        public IEnumerator Initialize()
        {
            Advertisement.debugMode = false;

            MetaData metaData = new MetaData("test");

            metaData.Set("serverUrl", "https://fake-ads-backend.applifier.info");
            metaData.Set("autoClose", "true");
            Advertisement.SetMetaData(metaData);

            Advertisement.Initialize("457");

            Assert.That(Advertisement.isInitialized, Is.True);
            Assert.That(Advertisement.isShowing, Is.False);

            while (!Advertisement.IsReady("defaultVideoAndPictureZone"))
            {
                yield return(null);
            }

            Assert.That(Advertisement.GetPlacementState("defaultVideoAndPictureZone"),
                        Is.EqualTo(PlacementState.Ready));
        }
Пример #16
0
    private void OnGUI()
    {
        if (Button("Init"))
        {
            Advertisement.Initialize(GAME_ID, true);
        }
        GUILayout.Label("inited:" + Advertisement.isInitialized, "box");
        if (!Advertisement.isInitialized)
        {
            return;
        }
        GUILayout.Label("isShowing" + Advertisement.isShowing);
        GUILayout.Label("chapin" + Advertisement.GetPlacementState("chapin_levelend"));
        GUILayout.Label("jili" + Advertisement.GetPlacementState("jili_levelend"));
        if (Button("load chapin"))
        {
            Advertisement.Load("chapin_levelend");
        }
        if (Button("load jili"))
        {
            Advertisement.Load("jili_levelend");
        }
        if (Button("chapin"))
        {
            Advertisement.Show("chapin_levelend");
        }

        if (Button("jili"))
        {
            Advertisement.Show("jili_levelend");
        }
        if (Button("test www"))
        {
            StartCoroutine(testURL("www.baidu.com"));
        }
    }
Пример #17
0
    public static void Reward(RewardDelegate onFinish, string placementId)
    {
        currentRewardId = placementId;
        onRewardWatched = onFinish;

        if (Advertisement.IsReady(currentRewardId))
        {
            Advertisement.Show(currentRewardId);
        }
        else
        {
            if (AdsManager.HasNoInternet())
            {
                onRewardWatched?.Invoke(new RewardResult(RewardResult.Type.LoadFailed, "No internet connection."));
            }
            else
            {
                //Manager.LoadingAnimation(true); //common AdsManager will handle turning off loading
                instance.RequestInterstitialNoShow(currentRewardId, (loadSuccess) =>
                {
                    if (loadSuccess)
                    {
                        Debug.Log("Load reward ad success");
                        Advertisement.Show(currentRewardId);
                    }
                    else
                    {
                        string error = "Unity Reward failed " + Advertisement.GetPlacementState(currentRewardId).ToString();
                        Debug.Log(error);
                        onRewardWatched?.Invoke(new RewardResult(RewardResult.Type.LoadFailed, error));
                        //AdsManager.ShowError(Advertisement.GetPlacementState(currentRewardId).ToString());
                    }
                }, showLoading: true);
            }
        }
    }
Пример #18
0
    public void ShowRewardedAd()
    {
        if (m_GameoverSelectionDone)
        {
            return;
        }

        m_GameoverSelectionDone = true;

#if UNITY_ADS
        if (Advertisement.IsReady(adsPlacementId))
        {
#if UNITY_ANALYTICS
            AnalyticsEvent.AdStart(adsRewarded, adsNetwork, adsPlacementId, new Dictionary <string, object>
            {
                { "level_index", PlayerData.instance.rank },
                { "distance", StageManager.instance == null ? 0 : StageManager.instance.playerPosZ },
            });
#endif
            var options = new ShowOptions {
                resultCallback = HandleShowResult
            };
            Advertisement.Show(adsPlacementId, options);
        }
        else
        {
#if UNITY_ANALYTICS
            AnalyticsEvent.AdSkip(adsRewarded, adsNetwork, adsPlacementId, new Dictionary <string, object> {
                { "error", Advertisement.GetPlacementState(adsPlacementId).ToString() }
            });
#endif
        }
#else
        GameOver();
#endif
    }