| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  | using System; | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  | using System.Collections; | 
					
						
							|  |  |  | using System.Collections.Generic; | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  | using System.Linq; | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  | using KwaiAds.Scripts.Api.Interstitial; | 
					
						
							|  |  |  | using KwaiAds.Scripts.Api.Reward; | 
					
						
							|  |  |  | using UnityEngine; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  | namespace WZ | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-02 09:14:49 +00:00
										 |  |  |     public class KwaiAdsManager : D_MonoSingleton<KwaiAdsManager>, IAdService | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         //目前都是测试id | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |         private string _appId = ""; | 
					
						
							|  |  |  |         private string _token = ""; | 
					
						
							|  |  |  |         public string _rewardAdUnitId = ""; | 
					
						
							|  |  |  |         public string _interstitialAdUnitId = ""; | 
					
						
							| 
									
										
										
										
											2025-09-02 09:14:49 +00:00
										 |  |  |         public double _rewardAdRevenue = -1; | 
					
						
							|  |  |  |         public double _interstitiaAdRevenue = -1; | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |         private IRewardAdController _rewardAdController; | 
					
						
							|  |  |  |         private IInterstitialAdController _interstitialAdController; | 
					
						
							|  |  |  |         public string _rvPos; | 
					
						
							|  |  |  |         public string _ivPos; | 
					
						
							|  |  |  |         public Action<bool, double> _rvCloseCallback = null; | 
					
						
							|  |  |  |         public Action<double> _ivCloseCallback = null; | 
					
						
							|  |  |  |         public Action _rvShowFailedCallback = null; | 
					
						
							|  |  |  |         public int _rewardRetryAttempt; | 
					
						
							|  |  |  |         public int _interRetryAttempt; | 
					
						
							|  |  |  |         public float _rvStartLoadTime = 0; | 
					
						
							|  |  |  |         public float _ivStartLoadTime = 0; | 
					
						
							|  |  |  |         public string ClientName => "Kwai"; | 
					
						
							|  |  |  |         public PlatformType Platfrom => PlatformType.Kwai; | 
					
						
							| 
									
										
										
										
											2025-09-02 15:25:00 +00:00
										 |  |  |          | 
					
						
							|  |  |  |         public bool _initialized { get; private set; } = false; | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         public void Initialize() | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-02 15:25:00 +00:00
										 |  |  |             LoggerUtils.Debug("KwaiAdsManager Initialize start" + _appId + " token:" + _token + " rewardAdUnitId:" + _rewardAdUnitId + " interstitialAdUnitId:" + _interstitialAdUnitId); | 
					
						
							|  |  |  |             if (string.IsNullOrEmpty(_appId) || string.IsNullOrEmpty(_token)|| _initialized) return; | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             var kwaiAdConfig = new KwaiAds.Scripts.Api.KwaiAdConfig.Builder() | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |                 .SetAppId(_appId) | 
					
						
							|  |  |  |                 .SetToken(_token) | 
					
						
							|  |  |  |                 .SetDebugLog(false) | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |                 .Build(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             KwaiAds.Scripts.Api.KwaiAdsSdk.Initialize(kwaiAdConfig, new InitResultCallbackImpl()); | 
					
						
							| 
									
										
										
										
											2025-09-02 15:25:00 +00:00
										 |  |  |             _initialized = true; | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |         public void RefreshAdsData() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             _appId = AdConfigParser.GetKwaiAppId(); | 
					
						
							|  |  |  |             _token = AdConfigParser.GetKwaiAppToken(); | 
					
						
							|  |  |  |             _rewardAdUnitId = AdConfigParser.GetKwaiAdUnits(AdsType.Rewarded).FirstOrDefault(); | 
					
						
							|  |  |  |             _interstitialAdUnitId = AdConfigParser.GetKwaiAdUnits(AdsType.Interstitial).FirstOrDefault(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |         #region 激励广告 | 
					
						
							|  |  |  |         public void LoadRewarded() | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |             if (string.IsNullOrEmpty(_rewardAdUnitId)) return; | 
					
						
							|  |  |  |             if (_rewardAdController != null) | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |                 _rewardAdController.Destroy(); | 
					
						
							|  |  |  |                 _rewardAdController = null; | 
					
						
							|  |  |  |                 _rewardAdRevenue = 0; | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |             _rewardAdController = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getRewardAdController(); | 
					
						
							|  |  |  |             KwaiRewardAdRequest kwaiRewardAdRequest = new KwaiRewardAdRequest(_rewardAdUnitId); | 
					
						
							|  |  |  |             _rewardAdController.Load(kwaiRewardAdRequest, new RewardAdListener(), new RewardAdLoadListener()); | 
					
						
							|  |  |  |             AdsActionEvents.TrackAdStartLoad(Platfrom, "", "", AdsType.Rewarded); | 
					
						
							|  |  |  |             _ivStartLoadTime = Time.realtimeSinceStartup; | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |         public bool IsRewardedAvailable() | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |             if (string.IsNullOrEmpty(_rewardAdUnitId)) return false; | 
					
						
							|  |  |  |             return _rewardAdController != null && _rewardAdController.IsReady(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public void DisplayRewarded(string _adPos, Action<bool, double> _rewardCallback = null, Action _showFailedCallback = null) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             _adPos = _rvPos; | 
					
						
							|  |  |  |             _rvCloseCallback = _rewardCallback; | 
					
						
							|  |  |  |             _rvShowFailedCallback = _showFailedCallback; | 
					
						
							|  |  |  |             if (_rewardAdController != null) | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |                 _rewardAdController.Show(); | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |                 _showFailedCallback?.Invoke(); | 
					
						
							|  |  |  |                 LoadRewarded(); | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |         public double GetRewardedRevenue() | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |             return _rewardAdRevenue; | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         #endregion | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         #region 插屏 | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |         public void LoadInterstitial() | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |             if (string.IsNullOrEmpty(_interstitialAdUnitId)) return; | 
					
						
							|  |  |  |             if (_interstitialAdController != null) | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |                 _interstitialAdController.Destroy(); | 
					
						
							|  |  |  |                 _interstitialAdController = null; | 
					
						
							|  |  |  |                 _interstitiaAdRevenue = 0; | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |             _interstitialAdController = KwaiAds.Scripts.Api.KwaiAdsSdk.SDK.getInterstitialAdController(); | 
					
						
							|  |  |  |             KwaiInterstitialAdRequest kwaiInterstitialAdRequest = new KwaiInterstitialAdRequest(_interstitialAdUnitId); | 
					
						
							|  |  |  |             _interstitialAdController.Load(kwaiInterstitialAdRequest, new InterstitialAdListener(), new InterstitialAdLoadListener()); | 
					
						
							|  |  |  |             AdsActionEvents.TrackAdStartLoad(Platfrom, "", "", AdsType.Interstitial); | 
					
						
							|  |  |  |             _ivStartLoadTime = Time.realtimeSinceStartup; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public bool IsInterstitialAvailable() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (string.IsNullOrEmpty(_interstitialAdUnitId)) return false; | 
					
						
							|  |  |  |             return _interstitialAdController != null && _interstitialAdController.IsReady(); | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |         public void DisplayInterstitial(string _adPos, IvType _IvType = IvType.IV1, Action<double> _closeCallback = null) | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |             _ivCloseCallback = _closeCallback; | 
					
						
							|  |  |  |             if (_interstitialAdController != null) | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |                 _interstitialAdController.Show(); | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |                 _closeCallback?.Invoke(0); | 
					
						
							|  |  |  |                 LoadInterstitial(); | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |         public double GetInterstitialRevenue() | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |             return _interstitiaAdRevenue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region 横幅广告功能 | 
					
						
							|  |  |  |         public void LoadBanner() { } | 
					
						
							|  |  |  |         public bool IsBannerAvailable() { return false; } | 
					
						
							|  |  |  |         public void DisplayBanner() { } | 
					
						
							|  |  |  |         public void HideBanner() { } | 
					
						
							|  |  |  |         public double GetBannerRevenue() { return 0; } | 
					
						
							|  |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region  开屏广告功能 | 
					
						
							|  |  |  |         public void LoadSplash() { } | 
					
						
							|  |  |  |         public bool IsSplashAvailable() { return false; } | 
					
						
							|  |  |  |         public void DisplaySplash() { } | 
					
						
							|  |  |  |         public double GetSplashRevenue() { return 0; } | 
					
						
							|  |  |  |         #endregion | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |         #region  原生广告功能 | 
					
						
							|  |  |  |         public void LoadNative() { } | 
					
						
							|  |  |  |         public bool IsNativeAvailable(string adUnitId) { return false; } | 
					
						
							|  |  |  |         public void DisplayNative(string _adPos, string adUnitId, NativeAdPosition position) { } | 
					
						
							|  |  |  |         public void RemoveNative(string adUnitId) { } | 
					
						
							|  |  |  |         public double GetNativeRevenue(string adUnitId) { return 0; } | 
					
						
							|  |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region  收益上报 | 
					
						
							|  |  |  |         public void TrackAdImpression(AdsType type) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             AdjustTrackEvent.Instance.TrackAdEvent(type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue, | 
					
						
							|  |  |  |                 ClientName, | 
					
						
							|  |  |  |                 type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId, | 
					
						
							|  |  |  |                 type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             FireBaseAnalyticsManager.Instance.OnAdRevenueEvent(ClientName, | 
					
						
							|  |  |  |                 ClientName, | 
					
						
							|  |  |  |                 type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId, | 
					
						
							|  |  |  |                 type, | 
					
						
							|  |  |  |                 type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue, | 
					
						
							|  |  |  |                 type == AdsType.Rewarded ? _rvPos : "", | 
					
						
							|  |  |  |                 AdPlayCountManager.GetAdPlayCount(type)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ShuShuEvent.Instance.OnAdRevenueEvent(ClientName, | 
					
						
							|  |  |  |                 ClientName, | 
					
						
							|  |  |  |                 type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId, | 
					
						
							|  |  |  |                 type.ToString(), | 
					
						
							|  |  |  |                 type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue, | 
					
						
							|  |  |  |                 type == AdsType.Rewarded ? _rvPos : "", | 
					
						
							|  |  |  |                 AdPlayCountManager.GetAdPlayCount(type)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             AdsActionEvents.TrackAdImpression(Platfrom, | 
					
						
							|  |  |  |                 ClientName, | 
					
						
							|  |  |  |                 type == AdsType.Rewarded ? _rewardAdUnitId : _interstitialAdUnitId, | 
					
						
							|  |  |  |                 type, | 
					
						
							|  |  |  |                 type == AdsType.Rewarded ? _rvPos : "", | 
					
						
							|  |  |  |                 type == AdsType.Rewarded ? _rewardAdRevenue : _interstitiaAdRevenue); | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-08-30 04:15:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  | } |