protected override void DownloadAd(AdStatusHandler ad) { if (AdsManager.Debugging) { Debug.Log("DownloadAd " + ad._Type.ToString() + " id " + ad._Id); } base.DownloadAd(ad); switch (ad._Type) { case AdsType.Banner: IronSource.Agent.loadBanner(IronSourceBannerSize.BANNER, AdapterBannerPosition(mBannerPosition)); break; case AdsType.Interstitial: IronSource.Agent.loadInterstitial(); break; } }
protected override void DownloadAd(AdStatusHandler ad) { if (AdsManager.Debugging) { Debug.Log("DownloadAd " + ad._Type.ToString() + " id " + ad._Id); } base.DownloadAd(ad); switch (ad._Type) { case AdsType.Banner: MaxSdk.CreateBanner(ad._Id, AdapterBannerPosition(mBannerPosition)); break; case AdsType.Interstitial: MaxSdk.LoadInterstitial(ad._Id); break; case AdsType.RewardedVideo: MaxSdk.LoadRewardedAd(ad._Id); break; } }
protected virtual void AdDownloadCallback(AdsType adType, bool result, string message) { if (mCurrentDownload == null) { if (AdsManager.Debugging) { Debug.Log("AdDownload mCurrentDownload is null but there is still have callback"); } return; } if (adType != mCurrentDownload._Type) { if (AdsManager.Debugging) { Debug.Log("AdDownload callback type " + adType + " does not match current download type " + mCurrentDownload._Type); } return; } if (result) { if (AdsManager.Debugging) { Debug.Log("AdDownload " + mCurrentDownload._Type + " id " + mCurrentDownload._Id + " result success"); } mAdLoadState = AdsLoadState.Loaded; } else { if (AdsManager.Debugging) { Debug.Log("AdDownload " + mCurrentDownload._Type + " id " + mCurrentDownload._Id + " result failed: " + message); } mAdLoadState = AdsLoadState.Error; } mCurrentDownload.OnAdAvailabilityUpdate(result); mCurrentDownload = null; }
protected override void UpdateDownloadList() { AdStatusHandler handler = null; if (AdsManager.I.IsAdEnabled(AdsType.RewardedVideo)) { handler = CreateAdHandler(AdsType.RewardedVideo, ""); mAdDownloadHandler.Add("rewardad", handler); mAdHighPriorityList.Add(handler); mDefaultRewardAdList.Add(handler); } if (AdsManager.I.IsAdEnabled(AdsType.OfferWall)) { handler = CreateAdHandler(AdsType.OfferWall, ""); mAdDownloadHandler.Add("offerwall", handler); mAdHighPriorityList.Add(handler); mDefaultOfferWallList.Add(handler); } if (AdsManager.I.IsAdEnabled(AdsType.Interstitial)) { handler = CreateAdHandler(AdsType.Interstitial, ""); mAdDownloadHandler.Add("interstitialad" + 0, handler); mAdHighPriorityList.Add(handler); mDefaultInterstitialAdList.Add(handler); } if (AdsManager.I.IsAdEnabled(AdsType.Banner)) { handler = CreateAdHandler(AdsType.Banner, ""); mAdDownloadHandler.Add("bannerad" + 0, handler); mAdHighPriorityList.Add(handler); mDefaultBannerAdList.Add(handler); } //Tin: not support sdk 6.16.1, currently Ironsource Option/Demanded Ad is messup too much, callback is not consistency //base.UpdateDownloadList(); }
protected override void DownloadAd(AdStatusHandler ad) { if (AdsManager.Debugging) { Debug.Log("DownloadAd " + ad._Type.ToString() + " id " + ad._Id); } base.DownloadAd(ad); switch (ad._Type) { case AdsType.Banner: { var newBannerAd = new BannerView(ad._Id, AdSize.Banner, AdapterBannerPosition(mBannerPosition)); var currentAdhandler = mCurrentDownload as AdmodAdStatusHandler; currentAdhandler.AssignData(newBannerAd); newBannerAd.OnAdOpening += (sender, args) => { UnityMainThreadDispatcher.instance.Enqueue(() => { BannerAdOpenedEvent(currentAdhandler); }); }; newBannerAd.OnAdLoaded += (sender, args) => { var backupSender = sender; UnityMainThreadDispatcher.instance.Enqueue(() => { BannerAdLoadedEvent(currentAdhandler, sender, null, true); }); }; newBannerAd.OnAdFailedToLoad += (sender, args) => { var backupSender = sender; var backupMsg = args.Message; UnityMainThreadDispatcher.instance.Enqueue(() => { BannerAdLoadedEvent(currentAdhandler, sender, backupMsg, false); }); }; // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the banner with the request. newBannerAd.LoadAd(request); } break; case AdsType.Interstitial: { var newInterstitialAd = new InterstitialAd(ad._Id); var currentAdhandler = mCurrentDownload as AdmodAdStatusHandler; currentAdhandler.AssignData(newInterstitialAd); newInterstitialAd.OnAdOpening += (sender, args) => { UnityMainThreadDispatcher.instance.Enqueue(() => { InterstitialAdOpenedEvent(currentAdhandler); }); }; newInterstitialAd.OnAdLoaded += (sender, args) => { var backupSender = sender; UnityMainThreadDispatcher.instance.Enqueue(() => { InterstitialAdLoadedEvent(currentAdhandler, sender, null, true); }); }; newInterstitialAd.OnAdFailedToLoad += (sender, args) => { var backupSender = sender; var backupMsg = args.Message; UnityMainThreadDispatcher.instance.Enqueue(() => { InterstitialAdLoadedEvent(currentAdhandler, sender, backupMsg, false); }); }; newInterstitialAd.OnAdClosed += (sender, args) => { UnityMainThreadDispatcher.instance.Enqueue(() => { InterstitialAdClosedEvent(currentAdhandler); }); }; // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the interstitial with the request. newInterstitialAd.LoadAd(request); } break; case AdsType.RewardedVideo: { var newRewardedAd = new RewardedAd(ad._Id); var currentAdhandler = mCurrentDownload as AdmodAdStatusHandler; currentAdhandler.AssignData(newRewardedAd); newRewardedAd.OnAdOpening += (sender, args) => { UnityMainThreadDispatcher.instance.Enqueue(() => { RewardedVideoAdOpenedEvent(currentAdhandler); }); }; newRewardedAd.OnAdLoaded += (sender, args) => { var backupSender = sender; UnityMainThreadDispatcher.instance.Enqueue(() => { RewardedVideoAdLoadedEvent(currentAdhandler, sender, null, true); }); }; newRewardedAd.OnAdFailedToLoad += (sender, args) => { var backupSender = sender; var backupMsg = args.Message; UnityMainThreadDispatcher.instance.Enqueue(() => { RewardedVideoAdLoadedEvent(currentAdhandler, sender, backupMsg, false); }); }; newRewardedAd.OnAdClosed += (sender, args) => { UnityMainThreadDispatcher.instance.Enqueue(() => { RewardedVideoAdClosedEvent(currentAdhandler); }); }; newRewardedAd.OnUserEarnedReward += (sender, args) => { UnityMainThreadDispatcher.instance.Enqueue(() => { RewardedVideoAdRewardedEvent(currentAdhandler); }); }; AdRequest request = new AdRequest.Builder().Build(); // Load the rewarded ad with the request. newRewardedAd.LoadAd(request); } break; } }
protected virtual void DownloadAd(AdStatusHandler ad) { mAdLoadState = AdsLoadState.Downloading; mCurrentDownload = ad; //Need each adapter to implement it's own code }
IEnumerator CRAutoRequestThread() { var highPriorityList = mAdHighPriorityList.ToArray(); var lowPriorityList = mAdLowPriorityList.ToArray(); if (highPriorityList.Length <= 0) { yield break; } int offsetIndex = 0; int errorCount = 0; float downloadTime = 0; AdStatusHandler lastDownloadHandler = null; while (true) { AdStatusHandler selectedDownload = null; for (int i = 0; i < highPriorityList.Length; ++i) { if (!highPriorityList[i].IsAvailable(0) && highPriorityList[i] != lastDownloadHandler) { selectedDownload = highPriorityList[i]; break; } } if (selectedDownload == null) { for (int i = 0; i < lowPriorityList.Length; ++i) { int index = (offsetIndex + i) % lowPriorityList.Length; if (!lowPriorityList[index].IsAvailable(0) && lowPriorityList[index] != lastDownloadHandler) { selectedDownload = lowPriorityList[index]; break; } } ++offsetIndex; } lastDownloadHandler = selectedDownload; if (selectedDownload != null) { while (mCurrentFullscreenAd != null || FullscreenAdShowing) { yield return(null); } DownloadAd(selectedDownload); downloadTime = 0; while (mAdLoadState == AdsLoadState.Downloading) { yield return(null); downloadTime += Time.deltaTime; if (downloadTime >= mConfig.GetDownloadTimeout()) { mAdLoadState = AdsLoadState.Error; if (selectedDownload != null) { AdDownloadCallback(selectedDownload._Type, false, "timeout"); } } } if (mAdLoadState == AdsLoadState.Error) { yield return(new WaitForSeconds(mConfig.GetErrorRetryInterval() + sAdsErrorDelayTime[Mathf.Min(errorCount, sAdsErrorDelayTime.Length - 1)])); ++errorCount; } else { errorCount = 0; } } yield return(null); } }
protected virtual void UpdateDownloadList() { var banners = mConfig.Platform.BannerlId.Split(';'); var interstitials = mConfig.Platform.InterstitialId.Split(';'); var rewards = mConfig.Platform.RewardedVideoId.Split(';'); var offerwalls = mConfig.Platform.OfferWallId.Split(';'); var bannerPlacements = mConfig.Platform.BannerAdPlacementConfig.Split(';'); var interstitialPlacements = mConfig.Platform.InterstitialAdPlacementConfig.Split(';'); var rewardPlacements = mConfig.Platform.RewardAdPlacementConfig.Split(';'); var offerwallPlacements = mConfig.Platform.OfferWallPlacementConfig.Split(';'); AdStatusHandler handler = null; if (rewards.Length > 0 && !string.IsNullOrEmpty(rewards[0])) { handler = CreateAdHandler(AdsType.RewardedVideo, rewards[0]); mAdDownloadHandler.Add(handler._Id, handler); mAdHighPriorityList.Add(handler); mDefaultRewardAdList.Add(handler); } if (offerwalls.Length > 0 && !string.IsNullOrEmpty(offerwalls[0])) { handler = CreateAdHandler(AdsType.OfferWall, offerwalls[0]); mAdDownloadHandler.Add(handler._Id, handler); mAdHighPriorityList.Add(handler); mDefaultOfferWallList.Add(handler); } if (interstitials.Length > 0 && !string.IsNullOrEmpty(interstitials[0])) { handler = CreateAdHandler(AdsType.Interstitial, interstitials[0]); mAdDownloadHandler.Add(handler._Id, handler); mAdHighPriorityList.Add(handler); mDefaultInterstitialAdList.Add(handler); } if (banners.Length > 0 && !string.IsNullOrEmpty(banners[0])) { handler = CreateAdHandler(AdsType.Banner, banners[0]); mAdDownloadHandler.Add(handler._Id, handler); mAdHighPriorityList.Add(handler); mDefaultBannerAdList.Add(handler); } int length = Mathf.Max(bannerPlacements.Length / 2, interstitialPlacements.Length / 2, rewardPlacements.Length / 2, offerwallPlacements.Length / 2); for (int i = 0; i < length; ++i) { int index = i * 2; if (index < rewardPlacements.Length && !mAdDownloadHandler.ContainsKey(rewardPlacements[index + 1])) { handler = CreateAdHandler(AdsType.RewardedVideo, rewardPlacements[index + 1]); mAdDownloadHandler.Add(handler._Id, handler); mAdLowPriorityList.Add(handler); } if (index < offerwallPlacements.Length && !mAdDownloadHandler.ContainsKey(offerwallPlacements[index + 1])) { handler = CreateAdHandler(AdsType.RewardedVideo, offerwallPlacements[index + 1]); mAdDownloadHandler.Add(handler._Id, handler); mAdLowPriorityList.Add(handler); } if (index < interstitialPlacements.Length && !mAdDownloadHandler.ContainsKey(interstitialPlacements[index + 1])) { handler = CreateAdHandler(AdsType.Interstitial, interstitialPlacements[index + 1]); mAdDownloadHandler.Add(handler._Id, handler); mAdLowPriorityList.Add(handler); } if (index < bannerPlacements.Length && !mAdDownloadHandler.ContainsKey(bannerPlacements[index + 1])) { handler = CreateAdHandler(AdsType.Banner, bannerPlacements[index + 1]); mAdDownloadHandler.Add(handler._Id, handler); mAdLowPriorityList.Add(handler); } } length = Mathf.Max(rewards.Length, interstitials.Length, banners.Length, offerwalls.Length); for (int i = 1; i < length; ++i) { if (i < rewards.Length && !mAdDownloadHandler.ContainsKey(rewards[i])) { handler = CreateAdHandler(AdsType.RewardedVideo, rewards[i]); mAdDownloadHandler.Add(handler._Id, handler); mAdLowPriorityList.Add(handler); mDefaultRewardAdList.Add(handler); } if (i < offerwalls.Length && !mAdDownloadHandler.ContainsKey(offerwalls[i])) { handler = CreateAdHandler(AdsType.RewardedVideo, offerwalls[i]); mAdDownloadHandler.Add(handler._Id, handler); mAdLowPriorityList.Add(handler); mDefaultOfferWallList.Add(handler); } if (i < interstitials.Length && !mAdDownloadHandler.ContainsKey(interstitials[i])) { handler = CreateAdHandler(AdsType.Interstitial, interstitials[i]); mAdDownloadHandler.Add(handler._Id, handler); mAdLowPriorityList.Add(handler); mDefaultInterstitialAdList.Add(handler); } if (i < banners.Length && !mAdDownloadHandler.ContainsKey(banners[i])) { handler = CreateAdHandler(AdsType.Banner, banners[i]); mAdDownloadHandler.Add(handler._Id, handler); mAdLowPriorityList.Add(handler); mDefaultBannerAdList.Add(handler); } } }