This commit is contained in:
2023-01-29 12:44:57 +08:00
commit b0c40a046f
358 changed files with 24287 additions and 0 deletions

View File

@@ -0,0 +1,163 @@
using AnyThinkAds.Api;
using AnyThinkAds.Common;
/// <summary>
/// @foldcc
/// 用于绑定旧版本的listener监听事件
/// </summary>
public class ADListenerAggregator
{
private ATRewardedVideoListener _awardVideoListener;
private ATInterstitialAdListener _interstitialListener;
public void BindAwardVideoListener(IATRewardedVideoAdClient client, ATRewardedVideoListener listener)
{
if (this._awardVideoListener == null)
{
client.onRewardEvent += this.onReward;
client.onAdClickEvent += this.onRewardedVideoAdPlayClicked;
client.onAdLoadEvent += this.onRewardedVideoAdLoaded;
client.onAdLoadFailureEvent += this.onRewardedVideoAdLoadFail;
client.onAdVideoEndEvent += this.onRewardedVideoAdPlayEnd;
client.onAdVideoCloseEvent += this.onRewardedVideoAdPlayClosed;
client.onAdVideoFailureEvent += this.onRewardedVideoAdPlayFail;
}
this._awardVideoListener = listener;
}
public void BindInterstitialAdListener(IATInterstitialAdClient client, ATInterstitialAdListener listener)
{
if (this._interstitialListener == null)
{
client.onAdLoadEvent += this.onInterstitialAdLoad;
client.onAdLoadFailureEvent += this.onInterstitialAdLoadFail;
client.onAdClickEvent += this.onInterstitialAdClick;
client.onAdCloseEvent += this.onInterstitialAdClose;
client.onAdShowEvent += this.onInterstitialAdShow;
client.onAdShowFailureEvent += this.onInterstitialAdFailedToShow;
}
this._interstitialListener = listener;
}
void onRewardedVideoAdLoaded(object sender, ATAdEventArgs callbackInfo)
{
this._awardVideoListener?.onRewardedVideoAdLoaded(callbackInfo.placementId);
}
/***
* The Ad load fail (note: for Android, all callback methods are not in the main thread of Unity)
*/
void onRewardedVideoAdLoadFail(object sender, ATAdErrorEventArgs callbackInfo)
{
this._awardVideoListener?.onRewardedVideoAdLoadFail(callbackInfo.placementId, callbackInfo.errorCode,
callbackInfo.errorMessage);
}
/***
* The Ad play end (note: for Android, all callback methods are not in the main thread of Unity)
*/
void onRewardedVideoAdPlayEnd(object sender, ATAdEventArgs callbackInfo)
{
this._awardVideoListener?.onRewardedVideoAdPlayEnd(callbackInfo.placementId, callbackInfo.callbackInfo);
}
/***
* The Ad play failnote: for Android, all callback methods are not in the main thread of Unity
* @param code error code
* @param message error message
*/
void onRewardedVideoAdPlayFail(object sender, ATAdErrorEventArgs callbackInfo)
{
this._awardVideoListener?.onRewardedVideoAdPlayFail(callbackInfo.placementId, callbackInfo.errorCode,
callbackInfo.errorMessage);
}
/**
* The Ad closenote: for Android, all callback methods are not in the main thread of Unity
* @param isReward
*/
void onRewardedVideoAdPlayClosed(object sender, ATAdRewardEventArgs callbackInfo)
{
this._awardVideoListener?.onRewardedVideoAdPlayClosed(callbackInfo.placementId, callbackInfo.isRewarded,
callbackInfo.callbackInfo);
}
/***
* The Ad clicknote: for Android, all callback methods are not in the main thread of Unity
*/
void onRewardedVideoAdPlayClicked(object sender, ATAdEventArgs callbackInfo)
{
this._awardVideoListener?.onRewardedVideoAdPlayClicked(callbackInfo.placementId, callbackInfo.callbackInfo);
}
/**
* The Ad rewardnote: for Android, all callback methods are not in the main thread of Unity
*/
private void onReward(object sender, ATAdEventArgs callbackInfo)
{
this._awardVideoListener?.onReward(callbackInfo.placementId, callbackInfo.callbackInfo);
}
/***
* 加载广告成功注意对于Android来说所有回调方法均不在Unity的主线程
* @param placementId 广告位id
*/
void onInterstitialAdLoad(object sender, ATAdEventArgs atAdEventArgs)
{
this._interstitialListener?.onInterstitialAdLoad(atAdEventArgs.placementId);
}
/***
* 加载广告失败注意对于Android来说所有回调方法均不在Unity的主线程
* @param placementId 广告位id
* @param code 错误码
* @param message 错误信息
*/
void onInterstitialAdLoadFail(object sender, ATAdErrorEventArgs atAdErrorEventArgs)
{
this._interstitialListener?.onInterstitialAdLoadFail(atAdErrorEventArgs.placementId,
atAdErrorEventArgs.errorCode, atAdErrorEventArgs.errorMessage);
}
/***
* 广告展示注意对于Android来说所有回调方法均不在Unity的主线程
* @param placementId 广告位id
*/
void onInterstitialAdShow(object sender, ATAdEventArgs atAdEventArgs)
{
this._interstitialListener?.onInterstitialAdShow(atAdEventArgs.placementId, atAdEventArgs.callbackInfo);
}
/***
* 广告展示失败注意对于Android来说所有回调方法均不在Unity的主线程
* @param placementId 广告位id
*/
void onInterstitialAdFailedToShow(object sender, ATAdErrorEventArgs atAdErrorEventArgs)
{
this._interstitialListener?.onInterstitialAdFailedToShow(atAdErrorEventArgs.placementId);
}
/***
* 广告关闭注意对于Android来说所有回调方法均不在Unity的主线程
* @param placementId 广告位id
*/
void onInterstitialAdClose(object sender, ATAdEventArgs atAdEventArgs)
{
this._interstitialListener?.onInterstitialAdClose(atAdEventArgs.placementId, atAdEventArgs.callbackInfo);
}
/***
* 广告点击注意对于Android来说所有回调方法均不在Unity的主线程
* @param placementId 广告位id
*/
void onInterstitialAdClick(object sender, ATAdEventArgs atAdEventArgs)
{
this._interstitialListener?.onInterstitialAdClick(atAdEventArgs.placementId, atAdEventArgs.callbackInfo);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: afdb282e107142e981754e553721cf94
timeCreated: 1674902675

View File

@@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using AnyThinkAds.Api;
using Runtime.ADAggregator;
using UnityEngine;
public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
{
private ATRewardedVideo _atRewardedVideo;
private Action<bool> _onVideoComplete;
private ADListenerAggregator _aggregator;
public override void OnInit()
{
this._atRewardedVideo = ATRewardedVideo.Instance;
// this._atRewardedVideo.client.setListener(this); //由于新版本广告sdk弃用该方式通过以下方式重新桥接监听事件
this._aggregator = new ADListenerAggregator();
this._aggregator.BindAwardVideoListener(this._atRewardedVideo.client , this);
// var adClient = this._atRewardedVideo.client;
// adClient.on
}
public override void ShowAD(Action onClose, Action<bool> onVideoComplete)
{
if (this.IsReadly())
{
this._onVideoComplete = onVideoComplete;
this.adListener.onClose = onClose;
this.adListener.onVideoComplete = this.OnVideoComplete;
this._atRewardedVideo.showAd(this.Key);
this.curState = 0;
}
}
private void OnVideoComplete(bool obj)
{
this._onVideoComplete?.Invoke(obj);
this._onVideoComplete = null;
}
public override bool IsReadly()
{
return this.curState == 2;
}
public override void LoadAD()
{
if (curState == 0)
{
{
Dictionary<string,string> jsonmap = new Dictionary<string,string>();
//ATConst.USERID_KEY必传用于标识每个用户;ATConst.USER_EXTRA_DATA为可选参数传入后将透传到开发者的服务器
jsonmap.Add(ATConst.USERID_KEY, ADManager.Instance.UserId);
jsonmap.Add(ATConst.USER_EXTRA_DATA, "user_extra_data");
curState = 1;
this._atRewardedVideo.loadVideoAd(this.Key, jsonmap);
}
}
}
#region SDK
public void onRewardedVideoAdLoaded(string placementId)
{
this.curState = 2;
}
public void onRewardedVideoAdLoadFail(string placementId, string code, string message)
{
Debug.LogError($"激励视频加载失败: {message} , code:{code} , placementId: {placementId}");
this.curState = 0;
}
public void onRewardedVideoAdPlayStart(string placementId, ATCallbackInfo callbackInfo)
{
}
public void onRewardedVideoAdPlayEnd(string placementId, ATCallbackInfo callbackInfo)
{
}
public void onRewardedVideoAdPlayFail(string placementId, string code, string message)
{
Debug.LogError($"激励视频播放失败: {message} , code:{code} , placementId: {placementId}");
curState = 0;
this.adListener.OnShowError();
}
public void onRewardedVideoAdPlayClosed(string placementId, bool isReward, ATCallbackInfo callbackInfo)
{
this.adListener.OnRewardVerify(isReward , 1 , "");
this.adListener.OnAdClose();
}
public void onRewardedVideoAdPlayClicked(string placementId, ATCallbackInfo callbackInfo)
{
}
public void onReward(string placementId, ATCallbackInfo callbackInfo)
{
this.adListener.OnRewardVerify(true , 1 , "");
this.adListener.OnAdClose();
}
public void startLoadingADSource(string placementId, ATCallbackInfo callbackInfo)
{
}
public void finishLoadingADSource(string placementId, ATCallbackInfo callbackInfo)
{
}
public void failToLoadADSource(string placementId, ATCallbackInfo callbackInfo, string code, string message)
{
this.OnError(code , message);
}
public void startBiddingADSource(string placementId, ATCallbackInfo callbackInfo)
{
}
public void finishBiddingADSource(string placementId, ATCallbackInfo callbackInfo)
{
}
public void failBiddingADSource(string placementId, ATCallbackInfo callbackInfo, string code, string message)
{
}
#endregion
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1091d31820014e7794cbbce68c61c84d
timeCreated: 1674895752

View File

@@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using AnyThinkAds.Api;
using Runtime.ADAggregator;
using UnityEngine;
public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
{
private ATInterstitialAd _atInterstitialAd;
private ADListenerAggregator _aggregator;
public override void OnInit()
{
this._atInterstitialAd = ATInterstitialAd.Instance;
this._aggregator = new ADListenerAggregator();
this._aggregator.BindInterstitialAdListener(this._atInterstitialAd.client,this);
}
public override void ShowAD(Action onClose, Action<bool> onVideoComplete)
{
if (curState == 2)
{
ATInterstitialAd.Instance.showInterstitialAd(this.Key);
curState = 0;
}
}
public override void LoadAD()
{
if (curState == 0)
{
{
//加载广告
Dictionary<string, object> jsonmap = new Dictionary<string, object>();
//只针对SigmobSigmob的激励视频广告源当做插屏使用
// jsonmap.Add(AnyThinkAds.Api.ATConst.USE_REWARDED_VIDEO_AS_INTERSTITIAL, AnyThinkAds.Api.ATConst.USE_REWARDED_VIDEO_AS_INTERSTITIAL_NO);
var width = (int) (Screen.width * 0.7f);
ATSize atSize = new ATSize(width, (int) (width * 1.5f));
jsonmap.Add(ATInterstitialAdLoadingExtra.kATInterstitialAdLoadingExtraInterstitialAdSizeStruct , atSize);
curState = 1;
this._atInterstitialAd.loadInterstitialAd(this.Key, jsonmap);
}
}
}
#region SDK
public void onInterstitialAdLoad(string placementId)
{
this.curState = 2;
}
public void onInterstitialAdLoadFail(string placementId, string code, string message)
{
this.curState = 0;
}
public void onInterstitialAdShow(string placementId, ATCallbackInfo callbackInfo)
{
}
public void onInterstitialAdFailedToShow(string placementId)
{
}
public void onInterstitialAdClose(string placementId, ATCallbackInfo callbackInfo)
{
this.adListener.OnAdClose();
this.adListener.OnShowComplete();
}
public void onInterstitialAdClick(string placementId, ATCallbackInfo callbackInfo)
{
}
public void onInterstitialAdStartPlayingVideo(string placementId, ATCallbackInfo callbackInfo)
{
}
public void onInterstitialAdEndPlayingVideo(string placementId, ATCallbackInfo callbackInfo)
{
}
public void onInterstitialAdFailedToPlayVideo(string placementId, string code, string message)
{
}
public void startLoadingADSource(string placementId, ATCallbackInfo callbackInfo)
{
}
public void finishLoadingADSource(string placementId, ATCallbackInfo callbackInfo)
{
}
public void failToLoadADSource(string placementId, ATCallbackInfo callbackInfo, string code, string message)
{
this.OnError(code , message);
}
public void startBiddingADSource(string placementId, ATCallbackInfo callbackInfo)
{
}
public void finishBiddingADSource(string placementId, ATCallbackInfo callbackInfo)
{
}
public void failBiddingADSource(string placementId, ATCallbackInfo callbackInfo, string code, string message)
{
this.OnError(code , message);
}
#endregion
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4b6e02b53a734744a4a4aba98087bc37
timeCreated: 1674903496

View File

@@ -0,0 +1,51 @@
using System;
using AnyThinkAds.Api;
using Runtime.ADAggregator;
public class ToponAdController : IAdController
{
private Action<bool> _maskAction;
private Action<string, string> _logEventAction;
private ADConfig _adConfig;
public void Init(ADConfig adConfig, object[] args)
{
_adConfig = adConfig;
ATSDKAPI.setChannel(args[0].ToString());
ATSDKAPI.setLogDebug(args.Length > 1 && (bool)args[1]);
ATSDKAPI.initSDK(adConfig.Id , adConfig.Key);
}
public void SetListener(Action<bool> adMaskAction ,Action<string, string> logEventAction)
{
_maskAction = adMaskAction;
_logEventAction = logEventAction;
}
public ADPlayer CreateAdPlayer(AD_Type type)
{
switch (type)
{
case AD_Type.AwardVideo:
var awardVideoPlayer = new AwardVideoPlayer();
return awardVideoPlayer.Init(_adConfig.BaseAwardAdKeyValue.value);
case AD_Type.Splash:
break;
case AD_Type.Interaction:
var interactionPlayer = new InteractionPlayer();
return interactionPlayer.Init(_adConfig.BaseInteractionAdKeyValue.value);
}
return null;
}
public void EventLog(string eventTable, string eventValue, string eventMessage = null)
{
_logEventAction?.Invoke(eventTable , eventValue);
}
public void SetMask(bool isOpen)
{
_maskAction?.Invoke(isOpen);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: eb67fd736cc0411d974ca91dda02b8a1
timeCreated: 1674964988