update: 添加广告启动配置, 添加 IAP 的购买广告的标志位
							parent
							
								
									a7d3a5147a
								
							
						
					
					
						commit
						c9301aa45e
					
				|  | @ -23,8 +23,6 @@ namespace Guru | |||
|         protected bool IsNetworkEnabled => Application.internetReachability != NetworkReachability.NotReachable; | ||||
| 
 | ||||
|         private bool _isServiceStarted; | ||||
|         protected bool _isDebugMode; | ||||
|         protected bool _isAutoLoadAds; | ||||
| 
 | ||||
|         private Action _onSdkInitReady; | ||||
|          | ||||
|  | @ -37,6 +35,7 @@ namespace Guru | |||
|         public static Action OnRewardFailed; | ||||
| 
 | ||||
|         private AdsModel _model; | ||||
|         private AdsInitSpec _initSpec = null; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// 启动广告服务 | ||||
|  | @ -44,13 +43,12 @@ namespace Guru | |||
|         /// <param name="callback">广告初始化回调</param> | ||||
|         /// <param name="autoLoadAds">自动启动广告加载</param> | ||||
|         /// <param name="isDebugMode">debug模式</param> | ||||
|         public virtual void StartService(Action callback = null, bool autoLoadAds = true, bool isDebugMode = false) | ||||
|         public virtual void StartService(Action callback = null, AdsInitSpec initSpec = null) | ||||
|         { | ||||
|             if (IsInitialized) return; // 已经初始化后, 无需再次初始化 | ||||
| 
 | ||||
|             _initSpec = initSpec; | ||||
|             _isServiceStarted = true; | ||||
|             _isAutoLoadAds = autoLoadAds; | ||||
|             _isDebugMode = isDebugMode; | ||||
|             _onSdkInitReady = callback; | ||||
|             _model = AdsModel.Create(); | ||||
|             this.Log("AD SDK Start Init"); | ||||
|  | @ -82,7 +80,8 @@ namespace Guru | |||
|             MaxSdkCallbacks.Rewarded.OnAdReceivedRewardEvent += OnRewardedAdReceivedRewardEvent; | ||||
| 
 | ||||
|             //-------------- SDK 初始化 ------------------- | ||||
|             MaxSdk.SetVerboseLogging(_isDebugMode); | ||||
|             if (_initSpec == null) _initSpec = AdsInitSpec.BuildDefault(); | ||||
|             MaxSdk.SetVerboseLogging(_initSpec.isDebug); | ||||
|             InitService(); | ||||
|         } | ||||
| 
 | ||||
|  | @ -94,16 +93,16 @@ namespace Guru | |||
|         private void OnMaxSdkInitializedCallBack(MaxSdkBase.SdkConfiguration sdkConfiguration) | ||||
|         { | ||||
|             this.Log("AD SDK Init Success"); | ||||
|             if (_isAutoLoadAds) OnMaxSdkReady(); | ||||
|             if (_initSpec.autoLoad) OnMaxSdkReady(); | ||||
|             _onSdkInitReady?.Invoke(); | ||||
|         } | ||||
| 
 | ||||
|         protected virtual void OnMaxSdkReady() | ||||
|         { | ||||
|             //TODO:各个项目根据自己情况进行修改,模版默认做法是SDK初始化完成后就进行广告请求 | ||||
|             RequestBannerAD(); | ||||
|             RequestInterstitialAD(); | ||||
|             RequestRewardedAD(); | ||||
|             //应用启动策略 | ||||
|             if(_initSpec.loadBanner) RequestBannerAD(); | ||||
|             if(_initSpec.loadInterstitial) RequestInterstitialAD(); | ||||
|             if(_initSpec.loadRewarded) RequestRewardedAD(); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|  | @ -115,6 +114,13 @@ namespace Guru | |||
|             return IsInitialized && IsNetworkEnabled; | ||||
|         } | ||||
| 
 | ||||
|         public bool IsBuyNoAds | ||||
|         { | ||||
|             get => _model.BuyNoAds; | ||||
|             set=> _model.BuyNoAds = value; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         #region ILRD | ||||
| 
 | ||||
|         private double TchAD001RevValue | ||||
|  |  | |||
|  | @ -0,0 +1,36 @@ | |||
| namespace Guru | ||||
| { | ||||
|     public class AdsInitSpec | ||||
|     { | ||||
|         public bool loadBanner; | ||||
|         public bool loadInterstitial; | ||||
|         public bool loadRewarded; | ||||
|         public bool autoLoad; | ||||
|         public bool isDebug; | ||||
| 
 | ||||
| 
 | ||||
|         public static AdsInitSpec Build(bool loadBanner = true, bool loadInterstitial = true, bool loadReward = true, | ||||
|             bool autoLoad = true, bool isDebug = false) | ||||
|         { | ||||
|             return new AdsInitSpec | ||||
|             { | ||||
|                 loadBanner = loadBanner, | ||||
|                 loadInterstitial = loadInterstitial, | ||||
|                 loadRewarded = loadReward, | ||||
|                 autoLoad = autoLoad, | ||||
|                 isDebug = isDebug | ||||
|             }; | ||||
|         } | ||||
|          | ||||
|         public static AdsInitSpec BuildDefault(bool autoLoad = true, bool isDebug = false) | ||||
|         { | ||||
|             return Build(true, true, true, autoLoad, isDebug); | ||||
|         } | ||||
|          | ||||
|         public static AdsInitSpec BuildWithNoAds(bool autoLoad = true, bool isDebug = false) | ||||
|         { | ||||
|             return Build(false, false, true, autoLoad, isDebug); | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,3 @@ | |||
| fileFormatVersion: 2 | ||||
| guid: 90685f9b1c664c4d917d7260f62b73ff | ||||
| timeCreated: 1710494122 | ||||
|  | @ -12,6 +12,7 @@ namespace Guru | |||
|         public int radsRewardCount = 0; | ||||
|         public double tchAd001Value = 0; | ||||
|         public double tchAd02Value = 0; | ||||
|         public bool buyNoAds = false; | ||||
|          | ||||
|          | ||||
|         public int RadsRewardCount | ||||
|  | @ -44,6 +45,17 @@ namespace Guru | |||
|             } | ||||
|         } | ||||
|          | ||||
|         public bool BuyNoAds | ||||
|         { | ||||
|             get => buyNoAds; | ||||
|             set | ||||
|             { | ||||
|                 buyNoAds = value; | ||||
|                 Save(); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|          | ||||
|         private void Save() => _storage.Save(); | ||||
| 
 | ||||
|         public string ToJson() | ||||
|  |  | |||
|  | @ -7,7 +7,7 @@ namespace Guru | |||
|          | ||||
|         #region Lifecycle | ||||
| 
 | ||||
|         void StartService(Action onSdkReady = null, bool autoLoad = true, bool isDebugMode = false); | ||||
|         void StartService(Action onSdkReady = null, AdsInitSpec spec = null); | ||||
| 
 | ||||
|         #endregion | ||||
|          | ||||
|  |  | |||
|  | @ -181,7 +181,7 @@ namespace Guru | |||
|                 var o = appleOrders[i]; | ||||
|                 if (o.Equals(order)) | ||||
|                 { | ||||
|                     googleOrders.RemoveAt(i); | ||||
|                     appleOrders.RemoveAt(i); | ||||
|                     Save(); | ||||
|                     return true; | ||||
|                 } | ||||
|  |  | |||
|  | @ -915,7 +915,7 @@ namespace Guru | |||
|          | ||||
|          | ||||
|         /// <summary> | ||||
|         /// 上报下一个 Google 订单 | ||||
|         /// 上报下一个订单数据 | ||||
|         /// </summary> | ||||
|         private void OnSendNextOrder() | ||||
|         { | ||||
|  | @ -923,19 +923,34 @@ namespace Guru | |||
|             { | ||||
|                 isOrderSending = true; | ||||
|                 var request = _orderRequests.Dequeue(); | ||||
|                 GoogleOrderRequest go = request as GoogleOrderRequest; | ||||
|                 AppleOrderRequest ao = request as AppleOrderRequest; | ||||
|        | ||||
|                 if (go != null  && _model.IsTokenExists(go.token)) | ||||
| 
 | ||||
|                 if (request == null) | ||||
|                 { | ||||
|                     OnSendNextOrder(); | ||||
|                     return; | ||||
|                 } | ||||
|                  | ||||
|                 if( ao != null && _model.IsReceiptExist(ao.receipt)) | ||||
| 
 | ||||
|                 GoogleOrderRequest go = request as GoogleOrderRequest; | ||||
|                 AppleOrderRequest ao = request as AppleOrderRequest; | ||||
|        | ||||
|                 if (go != null) | ||||
|                 { | ||||
|                     OnSendNextOrder(); | ||||
|                     return; | ||||
|                     if (_model.IsTokenExists(go.token)) | ||||
|                     { | ||||
|                         OnSendNextOrder(); | ||||
|                         return; | ||||
|                     } | ||||
|                     _model.AddGoogleOrder(go.orderData); // 尝试缓存 order  | ||||
|                 } | ||||
|                  | ||||
|                 if( ao != null) | ||||
|                 { | ||||
|                     if (_model.IsReceiptExist(ao.receipt)) | ||||
|                     { | ||||
|                         OnSendNextOrder(); | ||||
|                         return; | ||||
|                     } | ||||
|                     _model.AddAppleOrder(ao.orderData); // 尝试缓存 order  | ||||
|                 } | ||||
| 
 | ||||
|                 request.SetTimeOut(OrderRequestTimeout) | ||||
|  | @ -959,12 +974,10 @@ namespace Guru | |||
|                     { | ||||
|                         if (go != null) | ||||
|                         { | ||||
|                             _model.AddGoogleOrder(go.orderData); | ||||
|                             ReportGoogleOrderLost(go.orderData); | ||||
|                         } | ||||
|                         else if (ao != null) | ||||
|                         { | ||||
|                             _model.AddAppleOrder(ao.orderData); | ||||
|                             ReportAppleOrderLost(ao.orderData); | ||||
|                         } | ||||
|                          | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue