From aced9b0d1df3cf0b96fc20c52e73c695b2f94df2 Mon Sep 17 00:00:00 2001 From: huyufei Date: Tue, 9 Apr 2024 21:32:28 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E4=BC=98=E5=8C=96=E5=B9=BF=E5=91=8A?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91=E5=92=8C=20Loading=20?= =?UTF-8?q?=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/GuruCore/Runtime/Ads/ADService.cs | 2 ++ Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs | 32 +++++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Runtime/GuruCore/Runtime/Ads/ADService.cs b/Runtime/GuruCore/Runtime/Ads/ADService.cs index 2a6808c..7a754a2 100644 --- a/Runtime/GuruCore/Runtime/Ads/ADService.cs +++ b/Runtime/GuruCore/Runtime/Ads/ADService.cs @@ -124,6 +124,7 @@ namespace Guru public override void RequestInterstitialAD() { if (!IsInitialized) return; + if (IsIadsLoading) return; OnChannelLoadInterstitialAD(); } @@ -154,6 +155,7 @@ namespace Guru public override void RequestRewardedAD() { if (!IsInitialized) return; + if (IsRadsLoading) return; OnChannelLoadRewardAD(); } diff --git a/Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs b/Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs index 36f3efe..0468424 100644 --- a/Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs +++ b/Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs @@ -342,11 +342,15 @@ namespace Guru private int _interstitialRetryAttempt; protected float _iadsLoadStartTime; private Action _interstitialDismissAction; + protected bool _isIadsLoading = false; + public bool IsIadsLoading => _isIadsLoading; public virtual void RequestInterstitialAD() { - if (!CanLoadAds()) - return; + if (!CanLoadAds()) return; + + if(_isIadsLoading) return; + _isIadsLoading = true; LoadMaxInterstitial(); } @@ -368,9 +372,7 @@ namespace Guru public bool IsInterstitialADReady() { - if (!IsInitialized) - return false; - + if (!IsInitialized) return false; return MaxSdk.IsInterstitialReady(GetInterstitialID()); } @@ -398,11 +400,12 @@ namespace Guru _interstitialDismissAction = dismissAction; MaxSdk.ShowInterstitial(GetInterstitialID()); - RequestInterstitialAD(); // 直接加载下一个广告 + // RequestInterstitialAD(); // 直接加载下一个广告 } protected virtual void OnInterstitialLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) { + _isIadsLoading = false; // Interstitial ad is ready to be shown. MaxSdk.IsInterstitialReady(interstitialAdUnitId) will now return 'true' // Reset retry attempt // Analytics.ADIadsLoaded(adUnitId, GetAdsLoadDuration(ref _iadsLoadStartTime), _iadsCategory); @@ -415,6 +418,7 @@ namespace Guru protected virtual void OnInterstitialFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo) { + _isIadsLoading = false; // Interstitial ad failed to load // We recommend retrying with exponentially higher delays up to a maximum delay (in this case 64 seconds) this.LogError( @@ -477,12 +481,16 @@ namespace Guru private Action _rewardAction; private Action _failAction; private Action _dismissAction; + protected bool _isRadsLoading = false; + public bool IsRadsLoading => _isRadsLoading; public virtual void RequestRewardedAD() { - if (!IsInitialized) - return; + if (!CanLoadAds()) return; + if (_isRadsLoading) return; + _isRadsLoading = true; + LoadMaxRewardAd(); } @@ -492,6 +500,8 @@ namespace Guru /// protected void LoadMaxRewardAd(string unitId = "") { + if (IsRadsLoading) return; + OnLoadRads(); var id = GetRewardedVideoID(); Analytics.ADRadsLoad(AdParams.Build(id)); // 上报打点 @@ -539,11 +549,13 @@ namespace Guru _dismissAction = dismissAction; MaxSdk.ShowRewardedAd(GetRewardedVideoID()); - RequestRewardedAD(); + // RequestRewardedAD(); } protected virtual void OnRewardedAdLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) { + _isRadsLoading = false; + // Rewarded ad is ready to be shown. MaxSdk.IsRewardedAdReady(rewardedAdUnitId) will now return 'true' // Reset retry attempt // this.Log("OnRewardedAdLoadedEvent"); @@ -557,6 +569,8 @@ namespace Guru protected virtual void OnRewardedAdFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo) { + _isRadsLoading = false; + // Rewarded ad failed to load // We recommend retrying with exponentially higher delays up to a maximum delay (in this case 64 seconds) this.LogError(