296 lines
12 KiB
C#
296 lines
12 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using AnyThinkAds.Api;
|
|
using AnyThinkAds.ThirdParty.LitJson;
|
|
using UnityEngine;
|
|
|
|
namespace WZ
|
|
{
|
|
public class TpnAdsManager : NormalSingleton<TpnAdsManager>, IAdService
|
|
{
|
|
public string ClientName => "Topon";
|
|
public PlatformType Platfrom => PlatformType.Topon;
|
|
public string _topon_app_id;
|
|
public string _topon_app_key;
|
|
public string _topon_interstitial_units;
|
|
public string _topon_rewarded_units;
|
|
private string _rvPos;
|
|
private string _ivPos;
|
|
private Action<bool,double> _rvCloseCallback = null;
|
|
private Action<double> _ivCloseCallback = null;
|
|
private Action _rvShowFailedCallback = null;
|
|
|
|
public void Initialize()
|
|
{
|
|
|
|
LoggerUtils.Debug("[Tpn] 初始化 Tpn 广告 SDK appid:" + _topon_app_id + " appkey:" + _topon_app_key + " ivId:" + _topon_interstitial_units + " rvId:" + _topon_rewarded_units);
|
|
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();
|
|
}
|
|
}
|
|
|
|
public void RefreshAdsData()
|
|
{
|
|
_topon_app_id = AdConfigParser.GetTopOnAppId();
|
|
_topon_app_key = AdConfigParser.GetTopOnAppKey();
|
|
_topon_interstitial_units = AdConfigParser.GetTopOnAdUnits(AdsType.Interstitial).FirstOrDefault();
|
|
_topon_rewarded_units = AdConfigParser.GetTopOnAdUnits(AdsType.Rewarded).FirstOrDefault();
|
|
}
|
|
#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 });
|
|
|
|
AdsActionEvents.TrackAdStartLoad(Platfrom, "", "", AdsType.Rewarded);
|
|
|
|
}
|
|
public void LoadRewarded() { }
|
|
public void DisplayRewarded(string adPos, Action<bool,double> rewardCallback = null, Action showFailedCallback = null)
|
|
{
|
|
_rvPos = adPos;
|
|
_rvCloseCallback = rewardCallback;
|
|
_rvShowFailedCallback = showFailedCallback;
|
|
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 });
|
|
AdsActionEvents.TrackAdStartLoad(Platfrom,"","",AdsType.Interstitial);
|
|
}
|
|
|
|
public void LoadInterstitial() { }
|
|
public double GetInterstitialRevenue() { return 0; }
|
|
|
|
public void DisplayInterstitial(string ivPos, IvType _IvType = IvType.IV1, Action<double> closeCallback = null)
|
|
{
|
|
_ivPos = ivPos;
|
|
_ivCloseCallback = closeCallback;
|
|
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)
|
|
{
|
|
AdsActionEvents.TrackAdLoaded(Platfrom,
|
|
ClientName + "_" + erg.callbackInfo.network_firm_id,
|
|
erg.callbackInfo.adunit_id,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial,
|
|
0);
|
|
|
|
if (erg.placementId.Equals(_topon_interstitial_units))
|
|
{
|
|
LoggerUtils.Debug("[Tpn] ads tpn topon interstitial loaded");
|
|
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Interstitial);
|
|
}
|
|
else if (erg.placementId.Equals(_topon_rewarded_units))
|
|
{
|
|
LoggerUtils.Debug("[Tpn] ads tpn topon rewarded loaded");
|
|
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Rewarded);
|
|
}
|
|
}
|
|
|
|
private void OnAdLoadedFailEvent(object sender, ATAdErrorEventArgs erg)
|
|
{
|
|
LoggerUtils.Debug("[Tpn] 广告加载失败:" + JsonMapper.ToJson(erg.callbackInfo.toDictionary()));
|
|
AdsActionEvents.TrackAdFailToLoad(Platfrom,
|
|
ClientName + "_" + erg.callbackInfo.network_firm_id,
|
|
erg.callbackInfo.adunit_id,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial,
|
|
0,
|
|
erg.errorMessage);
|
|
}
|
|
|
|
private void OnAdVideoStartEvent(object sender, ATAdEventArgs erg)
|
|
{
|
|
LoggerUtils.Debug("[Tpn] 广告开始播放:" + JsonMapper.ToJson(erg.callbackInfo.toDictionary()));
|
|
|
|
TrackAdImpression(erg);
|
|
|
|
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()));
|
|
|
|
AdsActionEvents.TrackAdFailToShow(Platfrom,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial,
|
|
erg.errorMessage,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? _rvPos : "");
|
|
|
|
ThreadUtils.QueueOnMainThread(pObj =>
|
|
{
|
|
if (erg.placementId.Equals(_topon_rewarded_units))
|
|
{
|
|
_rvShowFailedCallback?.Invoke();
|
|
_rvShowFailedCallback = null;
|
|
}
|
|
else if (erg.placementId.Equals(_topon_interstitial_units))
|
|
{
|
|
_ivCloseCallback?.Invoke(0);
|
|
_ivCloseCallback = null;
|
|
}
|
|
}, "");
|
|
}
|
|
|
|
|
|
private void OnAdVideoClosedEvent(object sender, ATAdEventArgs erg)
|
|
{
|
|
LoggerUtils.Debug("[Tpn] 广告关闭了:" + JsonMapper.ToJson(erg.callbackInfo.toDictionary()));
|
|
|
|
AdsActionEvents.TrackAdClosed(Platfrom,
|
|
ClientName + "_" + erg.callbackInfo.network_firm_id,
|
|
erg.callbackInfo.adunit_id,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? _rvPos : "",
|
|
erg.callbackInfo.publisher_revenue);
|
|
|
|
ThreadUtils.QueueOnMainThread(pObj =>
|
|
{
|
|
if (erg.placementId.Equals(_topon_rewarded_units))
|
|
{
|
|
_rvCloseCallback?.Invoke(true,erg.callbackInfo.publisher_revenue);
|
|
_rvCloseCallback = null;
|
|
}
|
|
else if (erg.placementId.Equals(_topon_interstitial_units))
|
|
{
|
|
_ivCloseCallback?.Invoke(erg.callbackInfo.publisher_revenue);
|
|
_ivCloseCallback = null;
|
|
}
|
|
}, "");
|
|
}
|
|
|
|
private void OnAdVideoClickedEvent(object sender, ATAdEventArgs erg)
|
|
{
|
|
LoggerUtils.Debug("[Tpn] 点击广告了:" + JsonMapper.ToJson(erg.callbackInfo.toDictionary()));
|
|
|
|
AdsActionEvents.TrackAdClicked(Platfrom,
|
|
ClientName + "_" + erg.callbackInfo.network_firm_id,
|
|
erg.callbackInfo.adunit_id,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? _rvPos : "",
|
|
erg.callbackInfo.publisher_revenue);
|
|
|
|
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
|
|
|
|
#region 广告收益上报
|
|
public void TrackAdImpression(ATAdEventArgs erg)
|
|
{
|
|
AdjustTrackEvent.Instance.TrackAdEvent(erg.callbackInfo.publisher_revenue,
|
|
ClientName + "_" + erg.callbackInfo.network_firm_id,
|
|
erg.callbackInfo.adunit_id,
|
|
erg.callbackInfo.network_placement_id);
|
|
|
|
FireBaseAnalyticsManager.Instance.OnAdRevenueEvent(ClientName,
|
|
ClientName + "_" + erg.callbackInfo.network_firm_id,
|
|
erg.callbackInfo.adunit_id,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial,
|
|
erg.callbackInfo.publisher_revenue,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? _rvPos : "",
|
|
AdPlayCountManager.GetAdPlayCount(erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial));
|
|
|
|
ShuShuEvent.Instance.OnAdRevenueEvent(ClientName,
|
|
ClientName + "_" + erg.callbackInfo.network_firm_id,
|
|
erg.callbackInfo.adunit_id,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded.ToString() : AdsType.Interstitial.ToString(),
|
|
erg.callbackInfo.publisher_revenue,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? _rvPos : "",
|
|
AdPlayCountManager.GetAdPlayCount(erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial));
|
|
|
|
AdsActionEvents.TrackAdImpression(Platfrom,
|
|
ClientName + "_" + erg.callbackInfo.network_firm_id,
|
|
erg.callbackInfo.adunit_id,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? AdsType.Rewarded : AdsType.Interstitial,
|
|
erg.placementId.Equals(_topon_rewarded_units) ? _rvPos : "",
|
|
erg.callbackInfo.publisher_revenue);
|
|
}
|
|
#endregion
|
|
}
|
|
} |