| 
									
										
										
										
											2025-08-31 05:15:14 +00:00
										 |  |  | using System; | 
					
						
							| 
									
										
										
										
											2025-08-31 01:11:05 +00:00
										 |  |  | using System.Collections; | 
					
						
							|  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  | using System.Threading; | 
					
						
							|  |  |  | using AnyThinkAds.Api; | 
					
						
							|  |  |  | using AnyThinkAds.ThirdParty.LitJson; | 
					
						
							|  |  |  | using Script.Common; | 
					
						
							|  |  |  | using Script.SDKManager.AdsSDKManager.Utils; | 
					
						
							|  |  |  | using Script.Utils; | 
					
						
							|  |  |  | using SDK.Utils; | 
					
						
							|  |  |  | using SDKManager.AdsSDKManager.Constant; | 
					
						
							|  |  |  | using SDKManager.AdsSDKManager.Utils; | 
					
						
							|  |  |  | using UnityEngine; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Script.SDKManager.AdsSDKManager.TpnAdsManager | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public class TpnAdsManager : NormalSingleton<TpnAdsManager>, IAdService | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         public string ClientName => "Tpn"; | 
					
						
							|  |  |  |         public string topon_app_id;  | 
					
						
							|  |  |  |         public string topon_app_key;  | 
					
						
							|  |  |  |         public string topon_interstitial_units; | 
					
						
							|  |  |  |         public string topon_rewarded_units;  | 
					
						
							| 
									
										
										
										
											2025-08-31 05:15:14 +00:00
										 |  |  |         private string _rvPos; | 
					
						
							|  |  |  |         private string _ivPos; | 
					
						
							|  |  |  |         private Action<bool> _rvCloseCallback = null; | 
					
						
							|  |  |  |         private Action _ivCloseCallback = null; | 
					
						
							|  |  |  |         private Action _rvShowFailedCallback = null; | 
					
						
							| 
									
										
										
										
											2025-08-31 01:11:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         public void Initialize() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             topon_app_id = AdConfigParser.GetTopOnAppId(); | 
					
						
							|  |  |  |             topon_app_key = AdConfigParser.GetTopOnAppKey(); | 
					
						
							|  |  |  |             topon_interstitial_units = AdConfigParser.GetTopOnAdUnits(AdsType.Interstitial).ToArray()[0]; | 
					
						
							|  |  |  |             topon_rewarded_units = AdConfigParser.GetTopOnAdUnits(AdsType.Rewarded).ToArray()[0]; | 
					
						
							| 
									
										
										
										
											2025-08-31 05:15:14 +00:00
										 |  |  |             LoggerUtils.Debug("[Tpn] 初始化 Tpn 广告 SDK appid:" + topon_app_id + " appkey:" + topon_app_key + " ivId:" + topon_interstitial_units + " rvId:" + topon_rewarded_units); | 
					
						
							| 
									
										
										
										
											2025-08-31 01:11:05 +00:00
										 |  |  |             if (!string.IsNullOrEmpty(topon_app_id) && !string.IsNullOrEmpty(topon_app_key)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 ATSDKAPI.initSDK(topon_app_id, topon_app_key); | 
					
						
							|  |  |  |                 ATSDKAPI.setLogDebug(false); | 
					
						
							|  |  |  |                 // ATSDKAPI.showDebuggerUI(); | 
					
						
							|  |  |  |                 InitRewarded(); | 
					
						
							|  |  |  |                 InitInterstitial(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region 激励广告功能 | 
					
						
							|  |  |  |         private void InitRewarded() | 
					
						
							|  |  |  |         {  | 
					
						
							|  |  |  |             if (string.IsNullOrEmpty(topon_rewarded_units)) return; | 
					
						
							|  |  |  |             ATRewardedAutoVideo.Instance.client.onAdLoadEvent += OnAdLoadedEvent; | 
					
						
							|  |  |  |             ATRewardedAutoVideo.Instance.client.onAdLoadFailureEvent += OnAdLoadedFailEvent; | 
					
						
							|  |  |  |             ATRewardedAutoVideo.Instance.client.onAdVideoCloseEvent += OnAdVideoClosedEvent; | 
					
						
							|  |  |  |             ATRewardedAutoVideo.Instance.client.onAdVideoStartEvent += OnAdVideoStartEvent; | 
					
						
							|  |  |  |             ATRewardedAutoVideo.Instance.client.onAdVideoFailureEvent += OnAdVideoFailureEvent; | 
					
						
							|  |  |  |             ATRewardedAutoVideo.Instance.client.onAdClickEvent += OnAdVideoClickedEvent; | 
					
						
							|  |  |  |             ATRewardedAutoVideo.Instance.addAutoLoadAdPlacementID(new string[] { topon_rewarded_units }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         public void LoadRewarded() {} | 
					
						
							| 
									
										
										
										
											2025-08-31 05:15:14 +00:00
										 |  |  |         public void DisplayRewarded(string adPos, Action<bool> rewardCallback = null, Action showFailedCallback = null) | 
					
						
							| 
									
										
										
										
											2025-08-31 01:11:05 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-08-31 05:15:14 +00:00
										 |  |  |             _rvPos = adPos; | 
					
						
							|  |  |  |             _rvCloseCallback = rewardCallback; | 
					
						
							|  |  |  |             _rvShowFailedCallback = showFailedCallback; | 
					
						
							| 
									
										
										
										
											2025-08-31 01:11:05 +00:00
										 |  |  |             ATRewardedAutoVideo.Instance.showAutoAd(topon_rewarded_units); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public double GetRewardedRevenue() { return 0; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public bool IsRewardedAvailable() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return string.IsNullOrEmpty(topon_rewarded_units) ? false : ATRewardedAutoVideo.Instance.autoLoadRewardedVideoReadyForPlacementID(topon_rewarded_units); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region 插页广告功能 | 
					
						
							|  |  |  |         private void InitInterstitial() | 
					
						
							|  |  |  |         {  | 
					
						
							|  |  |  |             if (string.IsNullOrEmpty(topon_interstitial_units)) return; | 
					
						
							|  |  |  |             ATInterstitialAutoAd.Instance.client.onAdLoadEvent += OnAdLoadedEvent; | 
					
						
							|  |  |  |             ATInterstitialAutoAd.Instance.client.onAdLoadFailureEvent += OnAdLoadedFailEvent; | 
					
						
							|  |  |  |             ATInterstitialAutoAd.Instance.client.onAdCloseEvent += OnAdVideoClosedEvent; | 
					
						
							|  |  |  |             ATInterstitialAutoAd.Instance.client.onAdShowEvent += OnAdVideoStartEvent; | 
					
						
							|  |  |  |             ATInterstitialAutoAd.Instance.client.onAdShowFailureEvent += OnAdVideoFailureEvent; | 
					
						
							|  |  |  |             ATInterstitialAutoAd.Instance.client.onAdClickEvent += OnAdVideoClickedEvent; | 
					
						
							|  |  |  |             ATInterstitialAutoAd.Instance.addAutoLoadAdPlacementID(new string[] { topon_interstitial_units }); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public void LoadInterstitial(){} | 
					
						
							|  |  |  |         public double GetInterstitialRevenue(){return 0;} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-31 05:15:14 +00:00
										 |  |  |         public void DisplayInterstitial(string ivPos, IvType _IvType = IvType.IV1, Action closeCallback = null) | 
					
						
							| 
									
										
										
										
											2025-08-31 01:11:05 +00:00
										 |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-08-31 05:15:14 +00:00
										 |  |  |             _ivPos = ivPos; | 
					
						
							|  |  |  |             _ivCloseCallback = closeCallback; | 
					
						
							| 
									
										
										
										
											2025-08-31 01:11:05 +00:00
										 |  |  |             ATInterstitialAutoAd.Instance.showAutoAd(topon_interstitial_units); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public bool IsInterstitialAvailable() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return string.IsNullOrEmpty(topon_interstitial_units) ? false : ATInterstitialAutoAd.Instance.autoLoadInterstitialAdReadyForPlacementID(topon_interstitial_units); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region 代理 | 
					
						
							|  |  |  |         private void OnAdLoadedEvent(object sender, ATAdEventArgs erg) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (erg.placementId.Equals(topon_interstitial_units)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 LoggerUtils.Debug("[Tpn] ads tpn topon interstitial loaded"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else if (erg.placementId.Equals(topon_rewarded_units)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 LoggerUtils.Debug("[Tpn] ads tpn topon rewarded loaded"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void OnAdLoadedFailEvent(object sender, ATAdErrorEventArgs erg) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |            LoggerUtils.Debug("[Tpn] 广告加载失败:" + JsonMapper.ToJson(erg.callbackInfo.toDictionary())); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void OnAdVideoStartEvent(object sender, ATAdEventArgs erg) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             LoggerUtils.Debug("[Tpn] 广告开始播放:" + JsonMapper.ToJson(erg.callbackInfo.toDictionary())); | 
					
						
							|  |  |  |             // todo | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             ThreadUtils.QueueOnMainThread(pObj => | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (erg.placementId.Equals(topon_rewarded_units)) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else if (erg.placementId.Equals(topon_interstitial_units)) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }, ""); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void OnAdVideoFailureEvent(object sender, ATAdErrorEventArgs erg) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             LoggerUtils.Debug("[Tpn] 广告播放失败" + JsonMapper.ToJson(erg.callbackInfo.toDictionary())); | 
					
						
							|  |  |  |             ThreadUtils.QueueOnMainThread(pObj => | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (erg.placementId.Equals(topon_rewarded_units)) | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2025-08-31 05:15:14 +00:00
										 |  |  |                     _rvShowFailedCallback?.Invoke(); | 
					
						
							|  |  |  |                     _rvShowFailedCallback = null; | 
					
						
							| 
									
										
										
										
											2025-08-31 01:11:05 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 else if (erg.placementId.Equals(topon_interstitial_units)) | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2025-08-31 05:15:14 +00:00
										 |  |  |                     _ivCloseCallback?.Invoke(); | 
					
						
							|  |  |  |                     _ivCloseCallback = null; | 
					
						
							| 
									
										
										
										
											2025-08-31 01:11:05 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             }, ""); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void OnAdVideoClosedEvent(object sender, ATAdEventArgs erg) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             LoggerUtils.Debug("[Tpn] 广告关闭了:" + JsonMapper.ToJson(erg.callbackInfo.toDictionary())); | 
					
						
							|  |  |  |             ThreadUtils.QueueOnMainThread(pObj => | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (erg.placementId.Equals(topon_rewarded_units)) | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2025-08-31 05:15:14 +00:00
										 |  |  |                     _rvCloseCallback?.Invoke(true); | 
					
						
							|  |  |  |                     _rvCloseCallback = null; | 
					
						
							| 
									
										
										
										
											2025-08-31 01:11:05 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |                 else if (erg.placementId.Equals(topon_interstitial_units)) | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2025-08-31 05:15:14 +00:00
										 |  |  |                     _ivCloseCallback?.Invoke(); | 
					
						
							|  |  |  |                     _ivCloseCallback = null; | 
					
						
							| 
									
										
										
										
											2025-08-31 01:11:05 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             }, ""); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void OnAdVideoClickedEvent(object sender, ATAdEventArgs erg) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             LoggerUtils.Debug("[Tpn] 点击广告了:" + JsonMapper.ToJson(erg.callbackInfo.toDictionary())); | 
					
						
							|  |  |  |             ThreadUtils.QueueOnMainThread(pObj => | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (erg.placementId.Equals(topon_rewarded_units)) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 else if (erg.placementId.Equals(topon_interstitial_units)) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }, ""); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region 开屏广告功能 | 
					
						
							|  |  |  |         public void LoadSplash() { } | 
					
						
							|  |  |  |         public bool IsSplashAvailable() { return false; } | 
					
						
							|  |  |  |         public void DisplaySplash(){} | 
					
						
							|  |  |  |         public double GetSplashRevenue() {return 0;} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region 原生广告功能 | 
					
						
							|  |  |  |         public void LoadNative(){} | 
					
						
							|  |  |  |         public double GetNativeRevenue() {return 0;} | 
					
						
							|  |  |  |         public void DisplayNative(NativeAdPosition position){} | 
					
						
							|  |  |  |         public bool IsNativeAvailable(){return false;} | 
					
						
							|  |  |  |         public void RemoveNative(){} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region 横幅广告功能 | 
					
						
							|  |  |  |         public void LoadBanner(){} | 
					
						
							|  |  |  |         public bool IsBannerAvailable(){return false;} | 
					
						
							|  |  |  |         public void HideBanner(){} | 
					
						
							|  |  |  |         public double GetBannerRevenue(){return 0;} | 
					
						
							|  |  |  |         public void DisplayBanner(){} | 
					
						
							|  |  |  |         #endregion | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |