// 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; } }
public void Reward(RewardDelegate rewardDelegate, string placementId) { if (string.IsNullOrEmpty(placementId)) { rewardDelegate(new RewardResult(RewardResult.Type.LoadFailed, "FAN: Placement ID is empty")); } if (rewardedVideoAd != null) { rewardedVideoAd.Dispose(); } Manager.LoadingAnimation(true); onRewardWatched = rewardDelegate; rewardedVideoAd = new RewardedVideoAd(placementId); rewardedVideoAd.Register(gameObject); rewardedVideoAd.RewardedVideoAdDidLoad = RewardedVideoAdDidLoad; rewardedVideoAd.RewardedVideoAdDidFailWithError = RewardedVideoAdDidFailWithError; //rewardedVideoAd.RewardedVideoAdWillLogImpression //rewardedVideoAd.RewardedVideoAdDidClick rewardedVideoAd.RewardedVideoAdDidSucceed = RewardedVideoAdDidSucceed; rewardedVideoAd.RewardedVideoAdDidFail = RewardedVideoAdDidFail; rewardedVideoAd.RewardedVideoAdDidClose = RewardedVideoAdDidClose; #if UNITY_ANDROID //rewardedVideoAd.RewardedVideoAdActivityDestroyed #endif rewardedVideoAd.LoadAd(); }
void RewardedVideoAdDidClose() { onRewardWatched?.Invoke(new RewardResult(RewardResult.Type.Finished, string.Empty)); onRewardWatched = null; if (rewardedVideoAd != null) { rewardedVideoAd.Dispose(); } }
public void ShowInterstitialRewarded(AdPlacement.Type placeType, RewardDelegate onAdClosed = null) { if (currentRewardInterAdsHelper == null) { Debug.LogError("currentRewardInterAdsHelper is null due to all ads failed to load"); onAdClosed?.Invoke(new RewardResult(RewardResult.Type.LoadFailed)); return; } currentRewardInterAdsHelper.ShowInterstitialRewarded(placeType, onAdClosed); }
public void RequestInterstitialRewardedNoShow(AdPlacement.Type placementType, RewardDelegate onAdLoaded = null, bool showLoading = true) { if (IsAdsHiddenRemoteConfig(placementType)) { onAdLoaded?.Invoke(new RewardResult(RewardResult.Type.LoadFailed, "This Ads has been disabled")); return; } if (showLoading) { Manager.LoadingAnimation(true); } StartCoroutine(CoRequestInterstitialRewardedNoShow(placementType, onAdLoaded, showLoading)); timeLastShowInterstitial = time; }
//RewardedAd rewardBasedVideo; public static void RewardAdmob(RewardDelegate onFinish, string rewardVideoAdId = AdMobConst.REWARD_ID) { #if UNITY_EDITOR onFinish(new RewardResult(RewardResult.Type.Finished)); #else if (AdsManager.HasNoInternet()) { onFinish(new RewardResult(RewardResult.Type.LoadFailed, "No internet connection.")); } else if (AdMobManager.instance != null) { AdMobManager.instance.ShowRewardBasedVideo((rewarded) => { onFinish(rewarded); }, rewardVideoAdId); } #endif }
IEnumerator CoRequestInterstitialRewardedNoShow(AdPlacement.Type placementType, RewardDelegate onAdLoaded = null, bool showLoading = true) { RewardResult rewardResult = new RewardResult(); string errorMsg = string.Empty; WaitForSecondsRealtime checkInterval = new WaitForSecondsRealtime(0.05f); var adPriority = GetAdsNetworkPriority(placementType); for (int i = 0; i < adPriority.Count; i++) { bool checkAdNetworkDone = false; IAdsNetworkHelper adsHelper = GetAdsNetworkHelper(adPriority[i]); if (adsHelper == null) { continue; } adsHelper.RequestInterstitialRewardedNoShow(placementType, (success) => { checkAdNetworkDone = true; rewardResult = success; }); while (!checkAdNetworkDone) //Wait for ads load to complete { yield return(checkInterval); } if (rewardResult.type == RewardResult.Type.Finished) { currentRewardInterAdsHelper = adsHelper; break; } if (rewardResult.type == RewardResult.Type.Canceled) { break; } //if a reward ads was shown and user skipped it, stop looking for more ads } if (showLoading) { Manager.LoadingAnimation(false); } onAdLoaded?.Invoke(rewardResult); }
public void ShowRewardBasedVideo(RewardDelegate onVideoCompleted = null, string rewardVideoAdId = AdMobConst.REWARD_ID) { if (onVideoCompleted != null) { this.adsVideoRewardedCallback = onVideoCompleted; } //this.reward = false; rewardResult = new RewardResult(RewardResult.Type.Canceled); if (this.rewardBasedVideo.IsLoaded()) { this.showingAds = true; this.rewardBasedVideo.Show(); return; } Manager.LoadingAnimation(true); this.rewardBasedVideo.OnAdLoaded += RewardBasedVideo_OnAdLoaded; this.rewardBasedVideo.OnAdFailedToLoad += RewardBasedVideo_OnAdFailedToLoad; RequestRewardBasedVideo(rewardVideoAdId); StartCoroutine(CoTimeoutLoadReward()); }
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); } } }
public static void SetRewardDelegate(RewardDelegate callback) { Log.Debug("[AppEvents] SetRewardDelegate"); AppEventsImpl.SetRewardDelegate(callback); }
public void Reward(AdPlacementType placementId, RewardDelegate onFinish) { string id = CustomMediation.GetAdmobID(placementId, AdMobConst.REWARD_ID); RewardAdmob(onFinish, id); }
public void ShowInterstitialRewarded(AdPlacement.Type placementType, RewardDelegate onAdClosed) { onAdClosed?.Invoke(new RewardResult(RewardResult.Type.LoadFailed, "Not supported by Unity Ads")); }
public void RequestInterstitialRewardedNoShow(AdPlacement.Type placementType, RewardDelegate onFinish = null) { onFinish?.Invoke(new RewardResult(RewardResult.Type.LoadFailed, "Not supported by Unity Ads")); }
public void Reward(AdPlacement.Type placementType, RewardDelegate onFinish) { Reward(onFinish, CustomMediation.GetUnityPlacementId(placementType)); }