Tpn广告类
This commit is contained in:
parent
fa38e2509e
commit
4662ead100
|
@ -210,6 +210,7 @@ namespace Script.SDKManager.AdsSDKManager.AdmobAdsManager
|
|||
|
||||
public bool IsSplashAvailable()
|
||||
{
|
||||
if (!_initialized) return false;
|
||||
return _admobBannerAdManager.GetAvailableAdUnits().Count > 0;
|
||||
}
|
||||
public void DisplaySplash()
|
||||
|
@ -239,6 +240,7 @@ namespace Script.SDKManager.AdsSDKManager.AdmobAdsManager
|
|||
|
||||
private void OnSplashAdDismissed(string adUnitId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnSplashAdError(string adUnitId, int errorCode, string errorMsg)
|
||||
|
@ -296,6 +298,7 @@ namespace Script.SDKManager.AdsSDKManager.AdmobAdsManager
|
|||
|
||||
public bool IsBannerAvailable()
|
||||
{
|
||||
if (!_initialized) return false;
|
||||
return _admobBannerAdManager.GetAvailableAdUnits().Count > 0;
|
||||
}
|
||||
public void HideBanner()
|
||||
|
|
|
@ -181,15 +181,6 @@ namespace Script.SDKManager.AdsSDKManager.BigoAdsManager
|
|||
{
|
||||
return _interstitialAdManager.GetHighestPayingAdRevenue();
|
||||
}
|
||||
|
||||
// 从服务器获取广告位配置
|
||||
private List<string> GetInterstitialAdUnitsFromServer()
|
||||
{
|
||||
// 实现从服务器获取广告位ID列表的逻辑
|
||||
// todo
|
||||
return new List<string> { "bigo_interstitial_unit_1", "bigo_interstitial_unit_2", "bigo_interstitial_unit_3" };
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 开屏广告功能
|
||||
|
|
|
@ -0,0 +1,210 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using AnyThinkAds.Api;
|
||||
using AnyThinkAds.ThirdParty.LitJson;
|
||||
using NUnit.Framework.Internal;
|
||||
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;
|
||||
|
||||
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];
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
#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() {}
|
||||
public void DisplayRewarded()
|
||||
{
|
||||
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;}
|
||||
|
||||
public void DisplayInterstitial()
|
||||
{
|
||||
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))
|
||||
{
|
||||
|
||||
}
|
||||
else if (erg.placementId.Equals(topon_interstitial_units))
|
||||
{
|
||||
|
||||
}
|
||||
}, "");
|
||||
}
|
||||
|
||||
|
||||
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))
|
||||
{
|
||||
|
||||
}
|
||||
else if (erg.placementId.Equals(topon_interstitial_units))
|
||||
{
|
||||
|
||||
}
|
||||
}, "");
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fb96ca447b9164f92ad5f7fa33f7263f
|
|
@ -0,0 +1,178 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SDKManager.AdsSDKManager.Utils
|
||||
{
|
||||
public class ThreadUtils : MonoBehaviour
|
||||
{
|
||||
public static int maxThreads = 8;
|
||||
static int numThreads;
|
||||
|
||||
private static ThreadUtils _current;
|
||||
//private int _count;
|
||||
public static ThreadUtils Current
|
||||
{
|
||||
get
|
||||
{
|
||||
Initialize();
|
||||
return _current;
|
||||
}
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_current = this;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
static bool initialized;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
|
||||
if (!Application.isPlaying)
|
||||
return;
|
||||
initialized = true;
|
||||
var g = new GameObject("ThreadUtils");
|
||||
_current = g.AddComponent<ThreadUtils>();
|
||||
#if !ARTIST_BUILD
|
||||
UnityEngine.Object.DontDestroyOnLoad(g);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
public struct NoDelayedQueueItem
|
||||
{
|
||||
public Action<object> action;
|
||||
public object param;
|
||||
}
|
||||
|
||||
private List<NoDelayedQueueItem> _actions = new List<NoDelayedQueueItem>();
|
||||
public struct DelayedQueueItem
|
||||
{
|
||||
public float time;
|
||||
public Action<object> action;
|
||||
public object param;
|
||||
}
|
||||
private List<DelayedQueueItem> _delayed = new List<DelayedQueueItem>();
|
||||
|
||||
List<DelayedQueueItem> _currentDelayed = new List<DelayedQueueItem>();
|
||||
|
||||
public static void QueueOnMainThread(Action<object> taction, object tparam)
|
||||
{
|
||||
QueueOnMainThread(taction, tparam, 0f);
|
||||
}
|
||||
public static void QueueOnMainThread(Action<object> taction, object tparam, float time)
|
||||
{
|
||||
if (time != 0)
|
||||
{
|
||||
lock (Current._delayed)
|
||||
{
|
||||
Current._delayed.Add(new DelayedQueueItem { time = Time.time + time, action = taction, param = tparam });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lock (Current._actions)
|
||||
{
|
||||
Current._actions.Add(new NoDelayedQueueItem { action = taction, param = tparam });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Thread RunAsync(Action a)
|
||||
{
|
||||
Initialize();
|
||||
while (numThreads >= maxThreads)
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
Interlocked.Increment(ref numThreads);
|
||||
ThreadPool.QueueUserWorkItem(RunAction, a);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void RunAction(object action)
|
||||
{
|
||||
try
|
||||
{
|
||||
((Action)action)();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
Interlocked.Decrement(ref numThreads);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (_current == this)
|
||||
{
|
||||
|
||||
_current = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void ToukaGamesInit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
List<NoDelayedQueueItem> _currentActions = new List<NoDelayedQueueItem>();
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (_actions.Count > 0)
|
||||
{
|
||||
lock (_actions)
|
||||
{
|
||||
_currentActions.Clear();
|
||||
_currentActions.AddRange(_actions);
|
||||
_actions.Clear();
|
||||
}
|
||||
for (int i = 0; i < _currentActions.Count; i++)
|
||||
{
|
||||
_currentActions[i].action(_currentActions[i].param);
|
||||
}
|
||||
}
|
||||
|
||||
if (_delayed.Count > 0)
|
||||
{
|
||||
lock (_delayed)
|
||||
{
|
||||
_currentDelayed.Clear();
|
||||
_currentDelayed.AddRange(_delayed.Where(d => d.time <= Time.time));
|
||||
for (int i = 0; i < _currentDelayed.Count; i++)
|
||||
{
|
||||
_delayed.Remove(_currentDelayed[i]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < _currentDelayed.Count; i++)
|
||||
{
|
||||
_currentDelayed[i].action(_currentDelayed[i].param);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b1a8b2d9a81c545768a7085cbd43f3d5
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b09bfd714a0a94df2a20ba0d19e1496a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue