public IEnumerator ShowInterstitialAds(string placement, Action <AdFactory.RewardResult> OnFinish) { string id = ""; if (string.IsNullOrEmpty(placement)) { id = _defaultIterstitialPlacement; } else { if (!rewardPlacement.Contains(placement)) { rewardPlacement.Add(placement); } id = placement; } waitInterstitialAdFinish = false; if (Advertisement.IsReady(id)) { Advertisement.Show(id); } else { resultInterstitialAd = AdFactory.RewardResult.Faild; waitInterstitialAdFinish = true; } yield return(new WaitUntil(() => waitInterstitialAdFinish == true)); OnFinish(resultInterstitialAd); }
IEnumerator ShowRewardedAdsRunner(Action <AdFactory.RewardResult> OnFinish, string placement) { //顯示讀取,如果有的話 OnBeforeAdShow?.Invoke(); yield return(new WaitForSecondsRealtime(1f)); AdFactory.RewardResult result = AdFactory.RewardResult.Faild; #if UNITY_EDITOR result = EditorTestResult; #else if (CheckInit() && IsInternetAvaliable) { yield return(adManager.ShowRewardedAds(placement, (r) => { result = r; })); } else { yield return(new WaitForSecondsRealtime(1f)); Debug.Log("Video is not ready please check your network or try again later."); } #endif OnFinish?.Invoke(result); //關閉讀取,如果有的話 OnAfterAdShow?.Invoke(); OnAdResult?.Invoke(AdType.Reward, result, placement); }
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult) { if (placementId == _defaultRewaredPlacement || rewardPlacement.Contains(placementId)) { waitRewardedAdFinish = true; } else if (placementId == _defaultRewaredPlacement || iterstitialPlacament.Contains(placementId)) { waitInterstitialAdFinish = true; } switch (showResult) { case ShowResult.Finished: Debug.Log("The ad was successfully shown."); resultRewardAd = AdFactory.RewardResult.Success; break; case ShowResult.Skipped: Debug.Log("The ad was skipped before reaching the end."); resultRewardAd = AdFactory.RewardResult.Declined; break; case ShowResult.Failed: Debug.LogError("The ad failed to be shown."); resultRewardAd = AdFactory.RewardResult.Faild; break; } }
public IEnumerator ShowInterstitialAds(string placement, Action <AdFactory.RewardResult> callback) { string id = _defaultIterstitialPlacement; AdFactory.RewardResult result = AdFactory.RewardResult.Error; isInterstitialAdClose = false; int try_preload_times = 0; //等一秒,騙使用者很忙 yield return(new WaitForSecondsRealtime(1f)); //沒有讀到的情況 if (loadState_interstitialAds != AdFactory.AdsLoadState.Loaded) { while (try_preload_times < 2) { PreloadInterstitial(id); float wait = 0; while (wait < 2) { wait += Time.deltaTime; if (loadState_interstitialAds == AdFactory.AdsLoadState.Loaded) { goto SHOW; } yield return(null); } try_preload_times++; Debug.Log("Try load times : " + try_preload_times); } result = AdFactory.RewardResult.Faild; goto FINISH; } SHOW: if (interstitial != null) { if (interstitial.IsLoaded()) { result = AdFactory.RewardResult.Success; _ShowInterstitialAds(); } } while (!isInterstitialAdClose) { yield return(null); } FINISH: PreloadInterstitial(id); if (callback != null) { callback(result); } }
public IEnumerator ShowInterstitialAds(string placement, Action <AdFactory.RewardResult> OnComplete) { string id = _defaultIterstitialPlacement; AdFactory.RewardResult result = AdFactory.RewardResult.Error; isInterstitialShowFaild = false; isInterstitialAdClose = false; //等一秒,騙使用者很忙 yield return(new WaitForSecondsRealtime(0.5f)); //沒有讀到的情況 if (loadState_interstitialAds != AdFactory.AdsLoadState.Loaded) { PreloadInterstitial(id); float wait = 0; while (wait < 2) { wait += Time.deltaTime; if (loadState_interstitialAds == AdFactory.AdsLoadState.Loaded) { goto SHOW; } yield return(null); } result = AdFactory.RewardResult.Faild; goto FINISH; } SHOW: if (IronSource.Agent.isInterstitialReady()) { result = AdFactory.RewardResult.Success; _ShowInterstitialAds(); } while (!isInterstitialAdClose) { if (isInterstitialShowFaild) { result = AdFactory.RewardResult.Faild; goto FINISH; } yield return(null); } FINISH: PreloadInterstitial(id); if (OnComplete != null) { OnComplete(result); } }
public IEnumerator ShowRewardedAds(string placement, Action <AdFactory.RewardResult> OnFinish) { AdFactory.RewardResult result = AdFactory.RewardResult.Error; int try_preload_times = 0; isRewardAdClose = false; isRewarded = false; if (string.IsNullOrEmpty(placement)) { placement = _defaultRewaredPlacement; } rewardAdDict.TryGetValue(placement, out RewardedAd rewardedAd); if (rewardedAd == null) { rewardedAd = CreateAndLoadRewardedAd(placement); } yield return(new WaitForSecondsRealtime(0.2f)); //沒有讀到的情況 if (!rewardedAd.IsLoaded()) { while (try_preload_times < 3) { float wait = 0; while (wait < 1.5f) { wait += Time.deltaTime; if (rewardedAd.IsLoaded()) { goto SHOW; } yield return(null); } try_preload_times++; Debug.Log("Try load times : " + try_preload_times); } result = AdFactory.RewardResult.Faild; goto FINISH; } SHOW: if (rewardedAd.IsLoaded()) { rewardedAd.Show(); } else { result = AdFactory.RewardResult.Faild; goto FINISH; } while (isRewardAdClose == false) { yield return(null); } if (isRewarded) { result = AdFactory.RewardResult.Success; } else { result = AdFactory.RewardResult.Declined; } //Unbind Event rewardedAd.OnAdLoaded -= OnAdLoaded; rewardedAd.OnAdFailedToLoad -= OnAdFailedToLoad; rewardedAd.OnAdOpening -= OnAdOpening; rewardedAd.OnAdFailedToShow -= OnAdFailedToShow; rewardedAd.OnUserEarnedReward -= OnUserEarnedReward; rewardedAd.OnAdClosed -= OnAdClosed; CreateAndLoadRewardedAd(placement); FINISH: OnFinish?.Invoke(result); }
public IEnumerator ShowRewardedAds(string placement, Action <AdFactory.RewardResult> OnFinish) { AdFactory.RewardResult result = AdFactory.RewardResult.Error; int try_preload_times = 0; isRewardAdClose = false; isRewarded = false; isRewardShowFaild = false; if (string.IsNullOrEmpty(placement)) { placement = _defaultRewaredPlacement; } yield return(new WaitForSecondsRealtime(0.2f)); //沒有讀到的情況 if (!IronSource.Agent.isRewardedVideoAvailable()) { while (try_preload_times < 3) { float wait = 0; while (wait < 1.5f) { wait += Time.deltaTime; if (IronSource.Agent.isRewardedVideoAvailable()) { goto SHOW; } yield return(null); } try_preload_times++; Debug.Log("Try load times : " + try_preload_times); } result = AdFactory.RewardResult.Faild; goto FINISH; } SHOW: if (IronSource.Agent.isRewardedVideoAvailable()) { IronSource.Agent.showRewardedVideo(placement); } else { result = AdFactory.RewardResult.Faild; goto FINISH; } while (isRewardAdClose == false) { if (isRewardShowFaild) { result = AdFactory.RewardResult.Faild; goto FINISH; } yield return(null); } if (isRewarded) { result = AdFactory.RewardResult.Success; } else { result = AdFactory.RewardResult.Declined; } FINISH: OnFinish?.Invoke(result); }