diff --git a/Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs b/Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs index 2204d98..7169ba6 100644 --- a/Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs +++ b/Runtime/GuruCore/Runtime/Ads/ADServiceBase.cs @@ -22,6 +22,8 @@ namespace Guru public bool IsInitialized => MaxSdk.IsInitialized() || _isServiceStarted; protected bool IsNetworkEnabled => Application.internetReachability != NetworkReachability.NotReachable; + private const int MAX_ADS_RELOAD_INTERVAL = 6; // 广告加载最高时间为 2 的 6 次方 = 64秒 + private bool _isServiceStarted; protected Action _onSdkInitReady; @@ -149,6 +151,13 @@ namespace Guru set => Model.BuyNoAds = value; } + private float GetRetryDelaySeconds(int retryCount) + { + // 最低 2^retryCount 秒 + // 最高 2^6 = 64 秒 + return (float)Math.Pow(2, Math.Min(MAX_ADS_RELOAD_INTERVAL, retryCount)); + } + #region Lifecycele public void OnAppPaused(bool paused) @@ -511,8 +520,8 @@ namespace Guru this.LogError( $"OnInterstitialFailedEvent AdLoadFailureInfo:{errorInfo.AdLoadFailureInfo}, Message: {errorInfo.Message}"); _interstitialRetryAttempt++; - double retryDelay = Math.Pow(2, Math.Min(3, _interstitialRetryAttempt)); - DelayCall((float)retryDelay, RequestInterstitialAD); + float retryDelay = GetRetryDelaySeconds(_interstitialRetryAttempt); + DelayCall(retryDelay, RequestInterstitialAD); // Analytics.ADIadsFailed(adUnitId, (int)errorInfo.Code, GetAdsLoadDuration(ref _iadsLoadStartTime), _iadsCategory); Analytics.ADIadsFailed(AdParams.Build(adUnitId, duration: GetAdsLoadDuration(ref _iadsLoadStartTime), category: _iadsCategory, @@ -669,8 +678,8 @@ namespace Guru errorCode: (int)errorInfo.Code, waterfallName: errorInfo?.WaterfallInfo?.Name ?? "")); _rewardRetryAttempt++; - double retryDelay = Math.Pow(2, Math.Min(3, _rewardRetryAttempt)); - DelayCall((float)retryDelay, RequestRewardedAD); + float retryDelay = GetRetryDelaySeconds(_rewardRetryAttempt); + DelayCall(retryDelay, RequestRewardedAD); OnRewardFailed?.Invoke(); }