release: 1.4.7

This commit is contained in:
2026-04-22 17:44:49 +08:00
parent 79f478dd5f
commit e38e066a2d
37 changed files with 2598 additions and 78 deletions

View File

@@ -7,12 +7,15 @@ using UnityEngine;
public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
{
private ATRewardedVideo _atRewardedVideo;
private ATRewardedAutoVideo _atRewardedAutoVideo;
private Action<bool> _onVideoComplete;
private ADListenerAggregator _aggregator;
private bool _autoLoadRegistered;
public override void OnInit()
{
this._atRewardedVideo = ATRewardedVideo.Instance;
this._atRewardedAutoVideo = ATRewardedAutoVideo.Instance;
// this._atRewardedVideo.client.setListener(this); //由于新版本广告sdk弃用该方式通过以下方式重新桥接监听事件
this._aggregator = new ADListenerAggregator();
this._aggregator.BindAwardVideoListener(this._atRewardedVideo.client , this);
@@ -30,7 +33,15 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
this.adListener.onClose = onClose;
this.adListener.onVideoComplete = this.OnVideoComplete;
var json = new Dictionary<string, string> { { AnyThinkAds.Api.ATConst.SCENARIO, this.AdScene } };
this._atRewardedVideo.showAd(this.Key , json);
if (UseAutoLoad())
{
EnsureAutoLoadRegistered();
this._atRewardedAutoVideo.showAutoAd(this.Key, json);
}
else
{
this._atRewardedVideo.showAd(this.Key , json);
}
}
}
@@ -42,18 +53,54 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
public override bool IsReadly()
{
return this.curState == 2;
if (UseAutoLoad())
{
if (this._atRewardedAutoVideo != null &&
this._atRewardedAutoVideo.autoLoadRewardedVideoReadyForPlacementID(this.Key))
{
this.curState = 2;
return true;
}
return this.curState == 2;
}
if (this.curState == 2)
{
return true;
}
if (this._atRewardedVideo != null && this._atRewardedVideo.hasAdReady(this.Key))
{
this.curState = 2;
return true;
}
return false;
}
public override void LoadAD()
{
if (curState == 0)
{
if (UseAutoLoad())
{
EnsureAutoLoadRegistered();
this._atRewardedAutoVideo.setAutoLocalExtra(this.Key, BuildRewardedExtra());
this.curState = this._atRewardedAutoVideo.autoLoadRewardedVideoReadyForPlacementID(this.Key) ? 2 : 1;
return;
}
if (this._atRewardedVideo != null && this._atRewardedVideo.hasAdReady(this.Key))
{
this.curState = 2;
return;
}
{
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");
jsonmap = BuildRewardedExtra();
curState = 1;
this._atRewardedVideo.loadVideoAd(this.Key, jsonmap);
}
@@ -130,5 +177,63 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
}
#endregion
public override void OnPlayRequestStarted()
{
if (UseAutoLoad())
{
EnsureAutoLoadRegistered();
this._atRewardedAutoVideo?.setAutoLocalExtra(this.Key, BuildRewardedExtra());
}
}
public override int MaxLoadAttempts => ToponAdController.CurrentOptions?.RewardedMaxLoadAttempts ?? base.MaxLoadAttempts;
public override float LoadRetryDelaySeconds =>
Math.Max(0f, (ToponAdController.CurrentOptions?.RewardedLoadRetryDelayMs ?? 750) / 1000f);
public override bool AutoPreloadOnInit => ToponAdController.CurrentOptions?.RewardedPrewarmOnInit ?? true;
private bool UseAutoLoad()
{
return ToponAdController.CurrentOptions?.RewardedAutoLoad ?? true;
}
private void EnsureAutoLoadRegistered()
{
if (_autoLoadRegistered)
{
return;
}
this._atRewardedAutoVideo?.addAutoLoadAdPlacementID(new[] { this.Key });
_autoLoadRegistered = true;
}
private Dictionary<string, string> BuildRewardedExtra()
{
return new Dictionary<string, string>
{
{ ATConst.USERID_KEY, ADManager.Instance.UserId },
{ ATConst.USER_EXTRA_DATA, "user_extra_data" }
};
}
public override void EnterAdScenario(string scenario)
{
if (string.IsNullOrWhiteSpace(scenario) || string.Equals(scenario, "__default__", StringComparison.Ordinal))
{
return;
}
if (UseAutoLoad())
{
EnsureAutoLoadRegistered();
this._atRewardedAutoVideo?.entryAutoAdScenarioWithPlacementID(this.Key, scenario);
return;
}
this._atRewardedVideo?.entryScenarioWithPlacementID(this.Key, scenario);
}
}
}

View File

@@ -7,28 +7,83 @@ using UnityEngine;
public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
{
private ATInterstitialAd _atInterstitialAd;
private ATInterstitialAutoAd _atInterstitialAutoAd;
private ADListenerAggregator _aggregator;
private bool _autoLoadRegistered;
public override void OnInit()
{
this._atInterstitialAd = ATInterstitialAd.Instance;
this._atInterstitialAutoAd = ATInterstitialAutoAd.Instance;
this._aggregator = new ADListenerAggregator();
this._aggregator.BindInterstitialAdListener(this._atInterstitialAd.client,this);
}
public override void ShowAD(Action onClose, Action<bool> onVideoComplete)
{
if (curState == 2)
if (this.IsReadly())
{
ATInterstitialAd.Instance.showInterstitialAd(this.Key);
this.adListener.onClose = onClose;
this.adListener.onVideoComplete = onVideoComplete;
if (UseAutoLoad())
{
EnsureAutoLoadRegistered();
this._atInterstitialAutoAd.showAutoAd(this.Key, BuildInterstitialExtra());
}
else
{
ATInterstitialAd.Instance.showInterstitialAd(this.Key);
}
curState = 0;
}
}
public override bool IsReadly()
{
if (this.curState == 2)
{
return true;
}
if (UseAutoLoad())
{
if (this._atInterstitialAutoAd != null &&
this._atInterstitialAutoAd.autoLoadInterstitialAdReadyForPlacementID(this.Key))
{
this.curState = 2;
return true;
}
return false;
}
if (this._atInterstitialAd != null && this._atInterstitialAd.hasInterstitialAdReady(this.Key))
{
this.curState = 2;
return true;
}
return false;
}
public override void LoadAD()
{
if (curState == 0)
{
if (UseAutoLoad())
{
EnsureAutoLoadRegistered();
this._atInterstitialAutoAd.setAutoLocalExtra(this.Key, BuildInterstitialExtra());
this.curState = this._atInterstitialAutoAd.autoLoadInterstitialAdReadyForPlacementID(this.Key) ? 2 : 1;
return;
}
if (this._atInterstitialAd != null && this._atInterstitialAd.hasInterstitialAdReady(this.Key))
{
this.curState = 2;
return;
}
{
//加载广告
Dictionary<string, object> jsonmap = new Dictionary<string, object>();
@@ -61,6 +116,8 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
public void onInterstitialAdFailedToShow(string placementId)
{
this.curState = 0;
this.adListener.OnShowError();
}
public void onInterstitialAdClose(string placementId, ATCallbackInfo callbackInfo)
@@ -83,6 +140,8 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
public void onInterstitialAdFailedToPlayVideo(string placementId, string code, string message)
{
this.curState = 0;
this.adListener.OnShowError();
}
public void startLoadingADSource(string placementId, ATCallbackInfo callbackInfo)
@@ -112,4 +171,61 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
}
#endregion
}
public override void OnPlayRequestStarted()
{
if (UseAutoLoad())
{
EnsureAutoLoadRegistered();
this._atInterstitialAutoAd?.setAutoLocalExtra(this.Key, BuildInterstitialExtra());
}
}
public override int MaxLoadAttempts => ToponAdController.CurrentOptions?.InterstitialMaxLoadAttempts ?? base.MaxLoadAttempts;
public override float LoadRetryDelaySeconds =>
Math.Max(0f, (ToponAdController.CurrentOptions?.InterstitialLoadRetryDelayMs ?? 500) / 1000f);
public override bool AutoPreloadOnInit => ToponAdController.CurrentOptions?.InterstitialPrewarmOnInit ?? true;
private bool UseAutoLoad()
{
return ToponAdController.CurrentOptions?.InterstitialAutoLoad ?? true;
}
private void EnsureAutoLoadRegistered()
{
if (_autoLoadRegistered)
{
return;
}
this._atInterstitialAutoAd?.addAutoLoadAdPlacementID(new[] { this.Key });
_autoLoadRegistered = true;
}
private Dictionary<string, string> BuildInterstitialExtra()
{
return new Dictionary<string, string>
{
{ ATConst.SCENARIO, this.AdScene ?? string.Empty }
};
}
public override void EnterAdScenario(string scenario)
{
if (string.IsNullOrWhiteSpace(scenario) || string.Equals(scenario, "__default__", StringComparison.Ordinal))
{
return;
}
if (UseAutoLoad())
{
EnsureAutoLoadRegistered();
this._atInterstitialAutoAd?.entryAutoAdScenarioWithPlacementID(this.Key, scenario);
return;
}
this._atInterstitialAd?.entryScenarioWithPlacementID(this.Key, scenario);
}
}

View File

@@ -7,6 +7,7 @@ public class ToponAdController : IAdController
{
public static string LastDetectedArea { get; private set; }
public static string LastAreaError { get; private set; }
public static ToponControllerOptions CurrentOptions { get; private set; }
private Action<bool> _maskAction;
private Action<string, string> _logEventAction;
@@ -20,14 +21,16 @@ public class ToponAdController : IAdController
_adConfig = adConfig;
_controllerOptions = ToponControllerOptions.Resolve(adConfig, args);
CurrentOptions = _controllerOptions;
ApplyPreInitOptions(_controllerOptions);
var isDebug = _controllerOptions.Debug ?? false;
ATSDKAPI.setLogDebug(isDebug);
ATSDKAPI.initSDK(adConfig.Id , adConfig.Key);
StartChinaMainlandSdkIfNeeded();
ApplyPostInitOptions(_controllerOptions);
if (isDebug)
if (_controllerOptions.AutoOpenDebuggerUI)
{
ShowAndroidTest ();
}
@@ -103,6 +106,11 @@ public class ToponAdController : IAdController
return;
}
if (!string.IsNullOrWhiteSpace(options.LocalStrategyAssetPath))
{
ATSDKAPI.setLocalStrategyAssetPath(options.LocalStrategyAssetPath);
}
if (options.InitCustomMap != null && options.InitCustomMap.Count > 0)
{
ATSDKAPI.initCustomMap(options.InitCustomMap);
@@ -163,6 +171,26 @@ public class ToponAdController : IAdController
}
}
private static void StartChinaMainlandSdkIfNeeded()
{
#if UNITY_ANDROID && !UNITY_EDITOR
try
{
if (!ATSDKAPI.isCnSDK())
{
return;
}
ATSDKAPI.start();
Debug.Log("[Topon] Called ATSDK.start() for China mainland SDK.");
}
catch (Exception exception)
{
Debug.LogWarning($"[Topon] Failed to call ATSDK.start(): {exception.Message}");
}
#endif
}
private sealed class ToponAreaListener : ATGetAreaListener
{
private readonly ToponAdController _controller;

View File

@@ -11,6 +11,7 @@ public sealed class ToponControllerOptions
public const string SubChannelKey = "topon.sub_channel";
public const string DebugKey = "topon.debug";
public const string DebuggerKeyKey = "topon.debugger_key";
public const string AutoOpenDebuggerUiKey = "topon.auto_open_debugger_ui";
public const string SDKAreaKey = "topon.sdk_area";
public const string LongitudeKey = "topon.longitude";
public const string LatitudeKey = "topon.latitude";
@@ -19,11 +20,21 @@ public sealed class ToponControllerOptions
public const string QueryAreaOnInitKey = "topon.query_area_on_init";
public const string InitCustomMapKey = "topon.custom_map";
public const string RewardedCustomDataKey = "topon.rewarded_custom_data";
public const string RewardedAutoLoadKey = "topon.rewarded_auto_load";
public const string RewardedPrewarmOnInitKey = "topon.rewarded_prewarm_on_init";
public const string RewardedMaxLoadAttemptsKey = "topon.rewarded_max_load_attempts";
public const string RewardedLoadRetryDelayMsKey = "topon.rewarded_load_retry_delay_ms";
public const string InterstitialAutoLoadKey = "topon.interstitial_auto_load";
public const string InterstitialPrewarmOnInitKey = "topon.interstitial_prewarm_on_init";
public const string InterstitialMaxLoadAttemptsKey = "topon.interstitial_max_load_attempts";
public const string InterstitialLoadRetryDelayMsKey = "topon.interstitial_load_retry_delay_ms";
public const string LocalStrategyAssetPathKey = "topon.local_strategy_asset_path";
public string Channel { get; set; }
public string SubChannel { get; set; }
public bool? Debug { get; set; }
public string DebuggerKey { get; set; }
public bool AutoOpenDebuggerUI { get; set; }
public int? SDKArea { get; set; }
public double? Longitude { get; set; }
public double? Latitude { get; set; }
@@ -34,6 +45,15 @@ public sealed class ToponControllerOptions
public Dictionary<string, string> RewardedCustomData { get; set; }
public Action<string> OnAreaReceived { get; set; }
public Action<string> OnAreaError { get; set; }
public bool RewardedAutoLoad { get; set; } = true;
public bool RewardedPrewarmOnInit { get; set; } = true;
public int RewardedMaxLoadAttempts { get; set; } = 3;
public int RewardedLoadRetryDelayMs { get; set; } = 1000;
public bool InterstitialAutoLoad { get; set; } = true;
public bool InterstitialPrewarmOnInit { get; set; } = true;
public int InterstitialMaxLoadAttempts { get; set; } = 2;
public int InterstitialLoadRetryDelayMs { get; set; } = 500;
public string LocalStrategyAssetPath { get; set; }
public static ToponControllerOptions Resolve(ADConfig adConfig, object[] args)
{
@@ -85,6 +105,7 @@ public sealed class ToponControllerOptions
SubChannel = GetString(map, SubChannelKey, "sub_channel") ?? SubChannel;
Debug = GetBool(map, DebugKey, "debug") ?? Debug;
DebuggerKey = GetString(map, DebuggerKeyKey) ?? DebuggerKey;
AutoOpenDebuggerUI = GetBool(map, AutoOpenDebuggerUiKey) ?? AutoOpenDebuggerUI;
SDKArea = GetInt(map, SDKAreaKey) ?? SDKArea;
Longitude = GetDouble(map, LongitudeKey) ?? Longitude;
Latitude = GetDouble(map, LatitudeKey) ?? Latitude;
@@ -93,6 +114,15 @@ public sealed class ToponControllerOptions
QueryAreaOnInit = GetBool(map, QueryAreaOnInitKey) ?? QueryAreaOnInit;
InitCustomMap = MergeMaps(InitCustomMap, GetPrefixedMap(map, InitCustomMapKey + "."));
RewardedCustomData = MergeMaps(RewardedCustomData, GetPrefixedMap(map, RewardedCustomDataKey + "."));
RewardedAutoLoad = GetBool(map, RewardedAutoLoadKey) ?? RewardedAutoLoad;
RewardedPrewarmOnInit = GetBool(map, RewardedPrewarmOnInitKey) ?? RewardedPrewarmOnInit;
RewardedMaxLoadAttempts = GetInt(map, RewardedMaxLoadAttemptsKey) ?? RewardedMaxLoadAttempts;
RewardedLoadRetryDelayMs = GetInt(map, RewardedLoadRetryDelayMsKey) ?? RewardedLoadRetryDelayMs;
InterstitialAutoLoad = GetBool(map, InterstitialAutoLoadKey) ?? InterstitialAutoLoad;
InterstitialPrewarmOnInit = GetBool(map, InterstitialPrewarmOnInitKey) ?? InterstitialPrewarmOnInit;
InterstitialMaxLoadAttempts = GetInt(map, InterstitialMaxLoadAttemptsKey) ?? InterstitialMaxLoadAttempts;
InterstitialLoadRetryDelayMs = GetInt(map, InterstitialLoadRetryDelayMsKey) ?? InterstitialLoadRetryDelayMs;
LocalStrategyAssetPath = GetString(map, LocalStrategyAssetPathKey) ?? LocalStrategyAssetPath;
}
private void ApplyLegacyArgs(object[] args)
@@ -124,6 +154,7 @@ public sealed class ToponControllerOptions
SubChannel = explicitOptions.SubChannel ?? SubChannel;
Debug = explicitOptions.Debug ?? Debug;
DebuggerKey = explicitOptions.DebuggerKey ?? DebuggerKey;
AutoOpenDebuggerUI = explicitOptions.AutoOpenDebuggerUI || AutoOpenDebuggerUI;
SDKArea = explicitOptions.SDKArea ?? SDKArea;
Longitude = explicitOptions.Longitude ?? Longitude;
Latitude = explicitOptions.Latitude ?? Latitude;
@@ -174,6 +205,7 @@ public sealed class ToponControllerOptions
SubChannel = GetString(map, SubChannelKey, "sub_channel") ?? SubChannel;
Debug = GetBool(map, DebugKey, "debug") ?? Debug;
DebuggerKey = GetString(map, DebuggerKeyKey) ?? DebuggerKey;
AutoOpenDebuggerUI = GetBool(map, AutoOpenDebuggerUiKey) ?? AutoOpenDebuggerUI;
SDKArea = GetInt(map, SDKAreaKey) ?? SDKArea;
Longitude = GetDouble(map, LongitudeKey) ?? Longitude;
Latitude = GetDouble(map, LatitudeKey) ?? Latitude;
@@ -182,6 +214,15 @@ public sealed class ToponControllerOptions
QueryAreaOnInit = GetBool(map, QueryAreaOnInitKey) ?? QueryAreaOnInit;
InitCustomMap = MergeMaps(InitCustomMap, GetPrefixedMap(map, InitCustomMapKey + "."));
RewardedCustomData = MergeMaps(RewardedCustomData, GetPrefixedMap(map, RewardedCustomDataKey + "."));
RewardedAutoLoad = GetBool(map, RewardedAutoLoadKey) ?? RewardedAutoLoad;
RewardedPrewarmOnInit = GetBool(map, RewardedPrewarmOnInitKey) ?? RewardedPrewarmOnInit;
RewardedMaxLoadAttempts = GetInt(map, RewardedMaxLoadAttemptsKey) ?? RewardedMaxLoadAttempts;
RewardedLoadRetryDelayMs = GetInt(map, RewardedLoadRetryDelayMsKey) ?? RewardedLoadRetryDelayMs;
InterstitialAutoLoad = GetBool(map, InterstitialAutoLoadKey) ?? InterstitialAutoLoad;
InterstitialPrewarmOnInit = GetBool(map, InterstitialPrewarmOnInitKey) ?? InterstitialPrewarmOnInit;
InterstitialMaxLoadAttempts = GetInt(map, InterstitialMaxLoadAttemptsKey) ?? InterstitialMaxLoadAttempts;
InterstitialLoadRetryDelayMs = GetInt(map, InterstitialLoadRetryDelayMsKey) ?? InterstitialLoadRetryDelayMs;
LocalStrategyAssetPath = GetString(map, LocalStrategyAssetPathKey) ?? LocalStrategyAssetPath;
}
private static string GetString(IDictionary<string, string> map, params string[] keys)