You've already forked Commercialization.tapadn
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5810501618 |
@@ -1,3 +1,15 @@
|
||||
# [1.0.4]
|
||||
|
||||
### 新增
|
||||
|
||||
* 激励视频支持按游戏场景映射不同 TapADN SpaceId,并在未配置或配置非法时回退默认激励广告位。
|
||||
* 手动加载模式下激励视频缓存按 SpaceId 隔离,避免不同场景广告位串用 ready 缓存。
|
||||
* 激励视频缓存默认 10 分钟未消费自动销毁,可通过 `tapadn.rewarded_cache_max_age_seconds` 覆盖。
|
||||
|
||||
### 调整
|
||||
|
||||
* 智能预加载归因缓存增加 SpaceId 维度,避免多广告位场景下 ready/归因状态混用。
|
||||
|
||||
# [1.0.3]
|
||||
|
||||
### 修复
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Dirichlet.Mediation;
|
||||
using Runtime.ADAggregator;
|
||||
using UnityEngine;
|
||||
@@ -7,8 +8,11 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
||||
{
|
||||
private const float RewardCloseSettleDelaySeconds = 0.25f;
|
||||
|
||||
private readonly Dictionary<string, RewardedSlotCache> _slotCaches = new Dictionary<string, RewardedSlotCache>(StringComparer.Ordinal);
|
||||
|
||||
private DirichletAdNative _adNative;
|
||||
private DirichletRewardVideoAd _loadedAd;
|
||||
private string _defaultSlotId;
|
||||
private string _activeSlotId;
|
||||
private bool _rewardVerified;
|
||||
private bool _rewardVerifyReceived;
|
||||
private bool _closePendingRewardVerify;
|
||||
@@ -22,30 +26,46 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
||||
|
||||
public override void OnInit()
|
||||
{
|
||||
_defaultSlotId = Key;
|
||||
_adNative = DirichletAdManager.CreateAdNative();
|
||||
}
|
||||
|
||||
public override bool IsReadly()
|
||||
{
|
||||
var slotId = ResolveCurrentSlotId();
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
return TapadnAdRequestFactory.TryParseSlotId(Key, out _);
|
||||
return TapadnAdRequestFactory.TryParseSlotId(slotId, out _);
|
||||
}
|
||||
|
||||
if (_loadedAd != null && _loadedAd.IsLoaded && _loadedAd.IsValid)
|
||||
var cache = GetCache(slotId);
|
||||
if (IsCacheReady(cache))
|
||||
{
|
||||
curState = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cache != null && cache.Loading)
|
||||
{
|
||||
curState = 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cache != null)
|
||||
{
|
||||
RemoveCache(slotId);
|
||||
}
|
||||
|
||||
curState = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void LoadAD()
|
||||
{
|
||||
if (!TapadnAdRequestFactory.TryParseSlotId(Key, out _))
|
||||
var slotId = ResolveCurrentSlotId();
|
||||
if (!TapadnAdRequestFactory.TryParseSlotId(slotId, out _))
|
||||
{
|
||||
Debug.LogError($"[TapADN] Invalid rewarded slot id: {Key}");
|
||||
Debug.LogError($"[TapADN] Invalid rewarded slot id: {slotId}");
|
||||
curState = 0;
|
||||
return;
|
||||
}
|
||||
@@ -55,7 +75,7 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
||||
curState = 2;
|
||||
try
|
||||
{
|
||||
_adNative.PreLoad(TapadnAdRequestFactory.BuildRewarded(Key, TapadnAdController.CurrentOptions), 3);
|
||||
_adNative.PreLoad(TapadnAdRequestFactory.BuildRewarded(slotId, TapadnAdController.CurrentOptions), 3);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
@@ -64,33 +84,37 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
||||
return;
|
||||
}
|
||||
|
||||
if (curState == 1 || IsReadly())
|
||||
var cache = GetCache(slotId);
|
||||
if (cache != null && (cache.Loading || IsCacheReady(cache)))
|
||||
{
|
||||
curState = cache.Loading ? 1 : 2;
|
||||
return;
|
||||
}
|
||||
|
||||
cache = new RewardedSlotCache { Loading = true };
|
||||
_slotCaches[slotId] = cache;
|
||||
curState = 1;
|
||||
TapadnSmartLoadOrchestrator.OnLoadStarted(AD_Type.AwardVideo, AdScene);
|
||||
TapadnSmartLoadOrchestrator.OnLoadStarted(AD_Type.AwardVideo, AdScene, slotId);
|
||||
_adNative.LoadRewardVideoAd(
|
||||
TapadnAdRequestFactory.BuildRewarded(Key, TapadnAdController.CurrentOptions),
|
||||
TapadnAdRequestFactory.BuildRewarded(slotId, TapadnAdController.CurrentOptions),
|
||||
ad =>
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.AwardVideo, AdScene, true);
|
||||
_loadedAd?.Destroy();
|
||||
_loadedAd = ad;
|
||||
_loadedAd.Shown += OnManualShown;
|
||||
_loadedAd.Clicked += OnManualClicked;
|
||||
_loadedAd.ShowFailed += OnManualShowFailed;
|
||||
_loadedAd.RewardVerified += OnManualRewardVerify;
|
||||
_loadedAd.Closed += OnManualClosed;
|
||||
curState = 2;
|
||||
Debug.Log($"[TapADN] Rewarded loaded. slot={Key}");
|
||||
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.AwardVideo, AdScene, true, slotId);
|
||||
DestroyCachedAd(cache);
|
||||
cache.Ad = ad;
|
||||
cache.Loading = false;
|
||||
cache.LoadedUnix = GetNowUnixSeconds();
|
||||
RegisterManualEvents(slotId, cache.Ad);
|
||||
ScheduleCacheExpiration(slotId, cache);
|
||||
curState = string.Equals(slotId, ResolveCurrentSlotId(), StringComparison.Ordinal) ? 2 : curState;
|
||||
Debug.Log($"[TapADN] Rewarded loaded. scene={NormalizeScenario(AdScene)}, slot={slotId}");
|
||||
},
|
||||
error =>
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.AwardVideo, AdScene, false);
|
||||
curState = 0;
|
||||
Debug.LogError($"[TapADN] Rewarded load failed. code={error.Code}, message={error.Message}");
|
||||
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.AwardVideo, AdScene, false, slotId);
|
||||
RemoveCache(slotId);
|
||||
curState = string.Equals(slotId, ResolveCurrentSlotId(), StringComparison.Ordinal) ? 0 : curState;
|
||||
Debug.LogError($"[TapADN] Rewarded load failed. slot={slotId}, code={error.Code}, message={error.Message}");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -104,16 +128,20 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
||||
_showSettled = false;
|
||||
_rewardCloseSettleHandler?.Kill();
|
||||
_rewardCloseSettleHandler = null;
|
||||
_activeSlotId = ResolveCurrentSlotId();
|
||||
Key = _activeSlotId;
|
||||
curState = 0;
|
||||
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
_adNative.ShowRewardVideoAutoAd(TapadnAdRequestFactory.BuildRewarded(Key, TapadnAdController.CurrentOptions), this);
|
||||
_adNative.ShowRewardVideoAutoAd(TapadnAdRequestFactory.BuildRewarded(_activeSlotId, TapadnAdController.CurrentOptions), this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_loadedAd == null || !_loadedAd.Show())
|
||||
var cache = GetCache(_activeSlotId);
|
||||
if (!IsCacheReady(cache) || cache.Ad == null || !cache.Ad.Show())
|
||||
{
|
||||
RemoveCache(_activeSlotId);
|
||||
OnError(new DirichletError("show_failed", "ShowRewardVideoAd returned false"));
|
||||
return;
|
||||
}
|
||||
@@ -130,14 +158,14 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
||||
_rewardCloseSettleHandler?.Kill();
|
||||
_rewardCloseSettleHandler = null;
|
||||
curState = 0;
|
||||
TapadnSmartLoadOrchestrator.OnShowError(AD_Type.AwardVideo, AdScene);
|
||||
Debug.LogError($"[TapADN] Rewarded show failed. code={error?.Code}, message={error?.Message}");
|
||||
TapadnSmartLoadOrchestrator.OnShowError(AD_Type.AwardVideo, AdScene, _activeSlotId);
|
||||
Debug.LogError($"[TapADN] Rewarded show failed. slot={_activeSlotId}, code={error?.Code}, message={error?.Message}");
|
||||
adListener.OnShowError();
|
||||
}
|
||||
|
||||
public void OnAdShow()
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnShowStart(AD_Type.AwardVideo, AdScene);
|
||||
TapadnSmartLoadOrchestrator.OnShowStart(AD_Type.AwardVideo, AdScene, _activeSlotId);
|
||||
NotifyShowStarted();
|
||||
}
|
||||
|
||||
@@ -175,12 +203,23 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
||||
|
||||
public override void OnPlayRequestStarted()
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnPlayRequestStarted(AD_Type.AwardVideo, AdScene, !UseAutoLoad() && IsReadly());
|
||||
var slotId = ResolveCurrentSlotId();
|
||||
Key = slotId;
|
||||
TapadnSmartLoadOrchestrator.OnPlayRequestStarted(AD_Type.AwardVideo, AdScene, !UseAutoLoad() && IsReadly(), slotId);
|
||||
}
|
||||
|
||||
public override void EnterAdScenario(string scenario)
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnEnterAdScenario(AD_Type.AwardVideo, scenario, Key);
|
||||
AdScene = NormalizeScenario(scenario);
|
||||
var slotId = ResolveCurrentSlotId();
|
||||
Key = slotId;
|
||||
TapadnSmartLoadOrchestrator.OnEnterAdScenario(AD_Type.AwardVideo, AdScene, slotId);
|
||||
}
|
||||
|
||||
private string ResolveCurrentSlotId()
|
||||
{
|
||||
var slotId = TapadnAdController.CurrentOptions?.ResolveRewardedSlotId(_defaultSlotId, AdScene) ?? _defaultSlotId;
|
||||
return string.IsNullOrWhiteSpace(slotId) ? _defaultSlotId : slotId.Trim();
|
||||
}
|
||||
|
||||
private bool UseAutoLoad()
|
||||
@@ -188,8 +227,66 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
||||
return TapadnAdController.CurrentOptions?.RewardedAutoLoad ?? true;
|
||||
}
|
||||
|
||||
private void OnManualShown()
|
||||
private RewardedSlotCache GetCache(string slotId)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(slotId) && _slotCaches.TryGetValue(slotId, out var cache) ? cache : null;
|
||||
}
|
||||
|
||||
private bool IsCacheReady(RewardedSlotCache cache)
|
||||
{
|
||||
if (cache == null || cache.Loading || cache.Ad == null || !cache.Ad.IsLoaded || !cache.Ad.IsValid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var maxAgeSeconds = TapadnAdController.CurrentOptions?.RewardedCacheMaxAgeSeconds ?? 0;
|
||||
return maxAgeSeconds <= 0 || GetNowUnixSeconds() - cache.LoadedUnix <= maxAgeSeconds;
|
||||
}
|
||||
|
||||
private void RegisterManualEvents(string slotId, DirichletRewardVideoAd ad)
|
||||
{
|
||||
if (ad == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ad.Shown += () => OnManualShown(slotId);
|
||||
ad.Clicked += OnManualClicked;
|
||||
ad.ShowFailed += error => OnManualShowFailed(slotId, error);
|
||||
ad.RewardVerified += OnManualRewardVerify;
|
||||
ad.Closed += () => OnManualClosed(slotId);
|
||||
}
|
||||
|
||||
private void ScheduleCacheExpiration(string slotId, RewardedSlotCache cache)
|
||||
{
|
||||
cache.ExpireHandler?.Kill();
|
||||
cache.ExpireHandler = null;
|
||||
|
||||
var maxAgeSeconds = TapadnAdController.CurrentOptions?.RewardedCacheMaxAgeSeconds ?? 600;
|
||||
if (maxAgeSeconds <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cache.ExpireHandler = ADManager.Instance.CreateTimer(maxAgeSeconds, () =>
|
||||
{
|
||||
if (!ReferenceEquals(GetCache(slotId), cache))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"[TapADN] Rewarded cache expired. slot={slotId}, maxAgeSeconds={maxAgeSeconds}");
|
||||
RemoveCache(slotId);
|
||||
if (string.Equals(slotId, ResolveCurrentSlotId(), StringComparison.Ordinal))
|
||||
{
|
||||
curState = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void OnManualShown(string slotId)
|
||||
{
|
||||
_activeSlotId = slotId;
|
||||
OnAdShow();
|
||||
}
|
||||
|
||||
@@ -197,8 +294,9 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
||||
{
|
||||
}
|
||||
|
||||
private void OnManualShowFailed(DirichletError error)
|
||||
private void OnManualShowFailed(string slotId, DirichletError error)
|
||||
{
|
||||
RemoveCache(slotId);
|
||||
OnError(error);
|
||||
}
|
||||
|
||||
@@ -207,13 +305,49 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
||||
OnRewardVerify(args);
|
||||
}
|
||||
|
||||
private void OnManualClosed()
|
||||
private void OnManualClosed(string slotId)
|
||||
{
|
||||
_loadedAd?.Destroy();
|
||||
_loadedAd = null;
|
||||
RemoveCache(slotId);
|
||||
OnAdClose();
|
||||
}
|
||||
|
||||
private void RemoveCache(string slotId)
|
||||
{
|
||||
var cache = GetCache(slotId);
|
||||
if (cache == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DestroyCachedAd(cache);
|
||||
_slotCaches.Remove(slotId);
|
||||
}
|
||||
|
||||
private static void DestroyCachedAd(RewardedSlotCache cache)
|
||||
{
|
||||
if (cache?.Ad == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
cache.ExpireHandler?.Kill();
|
||||
cache.ExpireHandler = null;
|
||||
cache.Ad.Destroy();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogWarning($"[TapADN] Rewarded Destroy failed: {exception.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
cache.Ad = null;
|
||||
cache.Loading = false;
|
||||
cache.LoadedUnix = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void CompleteRewardedClose()
|
||||
{
|
||||
if (_showSettled)
|
||||
@@ -228,4 +362,22 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
||||
adListener.OnRewardVerify(_rewardVerified, TapadnAdController.CurrentOptions?.RewardAmount ?? 1, TapadnAdController.CurrentOptions?.RewardName ?? string.Empty);
|
||||
adListener.OnAdClose();
|
||||
}
|
||||
|
||||
private static string NormalizeScenario(string scenario)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(scenario) ? "__default__" : scenario.Trim();
|
||||
}
|
||||
|
||||
private static long GetNowUnixSeconds()
|
||||
{
|
||||
return (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
|
||||
}
|
||||
|
||||
private sealed class RewardedSlotCache
|
||||
{
|
||||
public DirichletRewardVideoAd Ad;
|
||||
public bool Loading;
|
||||
public long LoadedUnix;
|
||||
public AdTimeHandler ExpireHandler;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Runtime.ADAggregator;
|
||||
|
||||
public static class TapadnCommercialization
|
||||
@@ -31,4 +32,31 @@ public static class TapadnCommercialization
|
||||
config.BaseSplashAdKeyValue = new AdKeyValue { key = "splash", value = splashSlotId };
|
||||
return config;
|
||||
}
|
||||
|
||||
public static void SetRewardedSceneSlots(ADConfig config, IDictionary<string, string> sceneSlotIds)
|
||||
{
|
||||
if (config == null || sceneSlotIds == null || sceneSlotIds.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.CommonKeyValues == null)
|
||||
{
|
||||
config.CommonKeyValues = new List<AdKeyValue>();
|
||||
}
|
||||
|
||||
foreach (var entry in sceneSlotIds)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(entry.Key) || string.IsNullOrWhiteSpace(entry.Value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
config.CommonKeyValues.Add(new AdKeyValue
|
||||
{
|
||||
key = TapadnControllerOptions.RewardedSceneSlotPrefix + entry.Key.Trim(),
|
||||
value = entry.Value.Trim()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,10 @@ public sealed class TapadnControllerOptions
|
||||
public const string RewardedMaxLoadAttemptsKey = "tapadn.rewarded_max_load_attempts";
|
||||
public const string RewardedLoadRetryDelayMsKey = "tapadn.rewarded_load_retry_delay_ms";
|
||||
public const string RewardedShowTimeoutMsKey = "tapadn.rewarded_show_timeout_ms";
|
||||
public const string RewardedSceneSlotPrefix = "tapadn.rewarded_scene_slot.";
|
||||
public const string RewardedSceneSlotsKey = "tapadn.rewarded_scene_slots";
|
||||
public const string RewardedSceneSlotsJsonKey = "tapadn.rewarded_scene_slots_json";
|
||||
public const string RewardedCacheMaxAgeSecondsKey = "tapadn.rewarded_cache_max_age_seconds";
|
||||
public const string RewardNameKey = "tapadn.reward_name";
|
||||
public const string RewardAmountKey = "tapadn.reward_amount";
|
||||
public const string InterstitialAutoLoadKey = "tapadn.interstitial_auto_load";
|
||||
@@ -64,6 +68,8 @@ public sealed class TapadnControllerOptions
|
||||
public int RewardedMaxLoadAttempts { get; set; } = 1;
|
||||
public int RewardedLoadRetryDelayMs { get; set; } = 500;
|
||||
public int RewardedShowTimeoutMs { get; set; } = 20000;
|
||||
public int RewardedCacheMaxAgeSeconds { get; set; } = 600;
|
||||
public Dictionary<string, string> RewardedSceneSlotIds { get; private set; } = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
public string RewardName { get; set; } = "reward";
|
||||
public int RewardAmount { get; set; } = 1;
|
||||
public bool InterstitialAutoLoad { get; set; } = false;
|
||||
@@ -205,6 +211,11 @@ public sealed class TapadnControllerOptions
|
||||
RewardedMaxLoadAttempts = incoming.RewardedMaxLoadAttempts;
|
||||
RewardedLoadRetryDelayMs = incoming.RewardedLoadRetryDelayMs;
|
||||
RewardedShowTimeoutMs = incoming.RewardedShowTimeoutMs;
|
||||
RewardedCacheMaxAgeSeconds = incoming.RewardedCacheMaxAgeSeconds;
|
||||
if (incoming.RewardedSceneSlotIds != null && incoming.RewardedSceneSlotIds.Count > 0)
|
||||
{
|
||||
RewardedSceneSlotIds = CloneSceneSlotMap(incoming.RewardedSceneSlotIds);
|
||||
}
|
||||
RewardName = incoming.RewardName ?? RewardName;
|
||||
RewardAmount = incoming.RewardAmount;
|
||||
InterstitialAutoLoad = incoming.InterstitialAutoLoad;
|
||||
@@ -266,6 +277,8 @@ public sealed class TapadnControllerOptions
|
||||
RewardedMaxLoadAttempts = GetInt(map, RewardedMaxLoadAttemptsKey) ?? RewardedMaxLoadAttempts;
|
||||
RewardedLoadRetryDelayMs = GetInt(map, RewardedLoadRetryDelayMsKey) ?? RewardedLoadRetryDelayMs;
|
||||
RewardedShowTimeoutMs = GetInt(map, RewardedShowTimeoutMsKey) ?? RewardedShowTimeoutMs;
|
||||
RewardedCacheMaxAgeSeconds = Math.Max(0, GetInt(map, RewardedCacheMaxAgeSecondsKey) ?? RewardedCacheMaxAgeSeconds);
|
||||
ApplyRewardedSceneSlots(map);
|
||||
RewardName = GetString(map, RewardNameKey) ?? RewardName;
|
||||
RewardAmount = GetInt(map, RewardAmountKey) ?? RewardAmount;
|
||||
InterstitialAutoLoad = GetBool(map, InterstitialAutoLoadKey) ?? InterstitialAutoLoad;
|
||||
@@ -286,6 +299,116 @@ public sealed class TapadnControllerOptions
|
||||
ExpressHeight = GetInt(map, ExpressHeightKey) ?? ExpressHeight;
|
||||
}
|
||||
|
||||
public string ResolveRewardedSlotId(string defaultSlotId, string scenario)
|
||||
{
|
||||
var normalizedScenario = NormalizeScenario(scenario);
|
||||
if (RewardedSceneSlotIds != null &&
|
||||
RewardedSceneSlotIds.TryGetValue(normalizedScenario, out var mappedSlotId) &&
|
||||
TapadnAdRequestFactory.TryParseSlotId(mappedSlotId, out _))
|
||||
{
|
||||
return mappedSlotId;
|
||||
}
|
||||
|
||||
return defaultSlotId;
|
||||
}
|
||||
|
||||
private void ApplyRewardedSceneSlots(IDictionary<string, string> map)
|
||||
{
|
||||
foreach (var entry in map)
|
||||
{
|
||||
if (entry.Key == null || !entry.Key.StartsWith(RewardedSceneSlotPrefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var scene = entry.Key.Substring(RewardedSceneSlotPrefix.Length);
|
||||
AddRewardedSceneSlot(scene, entry.Value);
|
||||
}
|
||||
|
||||
ParseSceneSlotPairs(GetString(map, RewardedSceneSlotsKey), AddRewardedSceneSlot);
|
||||
ParseSceneSlotJson(GetString(map, RewardedSceneSlotsJsonKey), AddRewardedSceneSlot);
|
||||
}
|
||||
|
||||
private void AddRewardedSceneSlot(string scene, string slotId)
|
||||
{
|
||||
scene = NormalizeScenario(scene);
|
||||
if (string.IsNullOrWhiteSpace(slotId) || !TapadnAdRequestFactory.TryParseSlotId(slotId.Trim(), out _))
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"[TapADN] Ignore invalid rewarded scene slot. scene={scene}, slot={slotId}");
|
||||
return;
|
||||
}
|
||||
|
||||
RewardedSceneSlotIds[scene] = slotId.Trim();
|
||||
}
|
||||
|
||||
private static void ParseSceneSlotPairs(string value, Action<string, string> add)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value) || add == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var pairs = value.Split(new[] { ',', ';', '\n', '\r', '|' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (var pair in pairs)
|
||||
{
|
||||
var separatorIndex = pair.IndexOf('=');
|
||||
if (separatorIndex < 0)
|
||||
{
|
||||
separatorIndex = pair.IndexOf(':');
|
||||
}
|
||||
|
||||
if (separatorIndex <= 0 || separatorIndex >= pair.Length - 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
add(pair.Substring(0, separatorIndex), pair.Substring(separatorIndex + 1));
|
||||
}
|
||||
}
|
||||
|
||||
private static void ParseSceneSlotJson(string json, Action<string, string> add)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json) || add == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var parsed = JsonUtility.FromJson<TapadnSceneSlotMapConfig>(json);
|
||||
if (parsed?.Mappings == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var mapping in parsed.Mappings)
|
||||
{
|
||||
if (mapping == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
add(mapping.Scene, mapping.SlotId);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning($"[TapADN] Parse rewarded scene slot JSON failed: {exception.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> CloneSceneSlotMap(Dictionary<string, string> source)
|
||||
{
|
||||
return source == null
|
||||
? new Dictionary<string, string>(StringComparer.Ordinal)
|
||||
: new Dictionary<string, string>(source, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
private static string NormalizeScenario(string scenario)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(scenario) ? "__default__" : scenario.Trim();
|
||||
}
|
||||
|
||||
private static string GetString(IDictionary<string, string> map, params string[] keys)
|
||||
{
|
||||
foreach (var key in keys)
|
||||
@@ -383,4 +506,17 @@ public sealed class TapadnControllerOptions
|
||||
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
private sealed class TapadnSceneSlotMapConfig
|
||||
{
|
||||
public List<TapadnSceneSlotMapping> Mappings;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
private sealed class TapadnSceneSlotMapping
|
||||
{
|
||||
public string Scene;
|
||||
public string SlotId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,12 +56,12 @@ public sealed class TapadnInteractionPlayer : ADPlayer, IDirichletInterstitialAu
|
||||
}
|
||||
|
||||
curState = 1;
|
||||
TapadnSmartLoadOrchestrator.OnLoadStarted(AD_Type.Interaction, AdScene);
|
||||
TapadnSmartLoadOrchestrator.OnLoadStarted(AD_Type.Interaction, AdScene, Key);
|
||||
_adNative.LoadInterstitialAd(
|
||||
TapadnAdRequestFactory.BuildInterstitial(Key, TapadnAdController.CurrentOptions),
|
||||
ad =>
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.Interaction, AdScene, true);
|
||||
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.Interaction, AdScene, true, Key);
|
||||
_loadedAd?.Destroy();
|
||||
_loadedAd = ad;
|
||||
_loadedAd.Shown += OnManualShown;
|
||||
@@ -73,7 +73,7 @@ public sealed class TapadnInteractionPlayer : ADPlayer, IDirichletInterstitialAu
|
||||
},
|
||||
error =>
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.Interaction, AdScene, false);
|
||||
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.Interaction, AdScene, false, Key);
|
||||
curState = 0;
|
||||
Debug.LogError($"[TapADN] Interstitial load failed. code={error.Code}, message={error.Message}");
|
||||
});
|
||||
@@ -106,7 +106,7 @@ public sealed class TapadnInteractionPlayer : ADPlayer, IDirichletInterstitialAu
|
||||
}
|
||||
|
||||
_showSettled = true;
|
||||
TapadnSmartLoadOrchestrator.OnShowError(AD_Type.Interaction, AdScene);
|
||||
TapadnSmartLoadOrchestrator.OnShowError(AD_Type.Interaction, AdScene, Key);
|
||||
curState = 0;
|
||||
Debug.LogError($"[TapADN] Interstitial show failed. code={error?.Code}, message={error?.Message}");
|
||||
adListener.OnShowError();
|
||||
@@ -114,7 +114,7 @@ public sealed class TapadnInteractionPlayer : ADPlayer, IDirichletInterstitialAu
|
||||
|
||||
public void OnAdShow()
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnShowStart(AD_Type.Interaction, AdScene);
|
||||
TapadnSmartLoadOrchestrator.OnShowStart(AD_Type.Interaction, AdScene, Key);
|
||||
NotifyShowStarted();
|
||||
}
|
||||
|
||||
@@ -136,12 +136,13 @@ public sealed class TapadnInteractionPlayer : ADPlayer, IDirichletInterstitialAu
|
||||
|
||||
public override void OnPlayRequestStarted()
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnPlayRequestStarted(AD_Type.Interaction, AdScene, !UseAutoLoad() && IsReadly());
|
||||
TapadnSmartLoadOrchestrator.OnPlayRequestStarted(AD_Type.Interaction, AdScene, !UseAutoLoad() && IsReadly(), Key);
|
||||
}
|
||||
|
||||
public override void EnterAdScenario(string scenario)
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnEnterAdScenario(AD_Type.Interaction, scenario, Key);
|
||||
AdScene = string.IsNullOrWhiteSpace(scenario) ? "__default__" : scenario.Trim();
|
||||
TapadnSmartLoadOrchestrator.OnEnterAdScenario(AD_Type.Interaction, AdScene, Key);
|
||||
}
|
||||
|
||||
private bool UseAutoLoad()
|
||||
@@ -151,7 +152,7 @@ public sealed class TapadnInteractionPlayer : ADPlayer, IDirichletInterstitialAu
|
||||
|
||||
private void OnManualShown()
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnShowStart(AD_Type.Interaction, AdScene);
|
||||
TapadnSmartLoadOrchestrator.OnShowStart(AD_Type.Interaction, AdScene, Key);
|
||||
NotifyShowStarted();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public static class TapadnSmartLoadOrchestrator
|
||||
private static TapadnSmartLoadConfig _runtimeConfig;
|
||||
private static Dictionary<string, TapadnSmartLoadSceneState> _states = new Dictionary<string, TapadnSmartLoadSceneState>(StringComparer.Ordinal);
|
||||
private static Dictionary<string, TapadnSmartLoadPolicyItem> _policies = new Dictionary<string, TapadnSmartLoadPolicyItem>(StringComparer.Ordinal);
|
||||
private static Dictionary<int, TapadnSmartLoadCacheState> _cacheStates = new Dictionary<int, TapadnSmartLoadCacheState>();
|
||||
private static Dictionary<string, TapadnSmartLoadCacheState> _cacheStates = new Dictionary<string, TapadnSmartLoadCacheState>(StringComparer.Ordinal);
|
||||
private static bool _initialized;
|
||||
private static bool _enabled;
|
||||
|
||||
@@ -116,7 +116,7 @@ public static class TapadnSmartLoadOrchestrator
|
||||
_enabled = options?.SmartPreloadEnabled ?? false;
|
||||
_initialized = true;
|
||||
_states = new Dictionary<string, TapadnSmartLoadSceneState>(StringComparer.Ordinal);
|
||||
_cacheStates = new Dictionary<int, TapadnSmartLoadCacheState>();
|
||||
_cacheStates = new Dictionary<string, TapadnSmartLoadCacheState>(StringComparer.Ordinal);
|
||||
LoadStates();
|
||||
EnsureDefaultPolicies(_runtimeConfig);
|
||||
}
|
||||
@@ -135,10 +135,10 @@ public static class TapadnSmartLoadOrchestrator
|
||||
record.ShowRequestCount = Math.Max(0, record.ShowRequestCount);
|
||||
SaveStates();
|
||||
|
||||
TryPreload(adType, normalizedScenario);
|
||||
TryPreload(adType, normalizedScenario, _slotId);
|
||||
}
|
||||
|
||||
public static void OnPlayRequestStarted(AD_Type adType, string scenario, bool cacheReadyAtRequest)
|
||||
public static void OnPlayRequestStarted(AD_Type adType, string scenario, bool cacheReadyAtRequest, string slotId = null)
|
||||
{
|
||||
if (!_initialized || !_enabled)
|
||||
{
|
||||
@@ -152,49 +152,49 @@ public static class TapadnSmartLoadOrchestrator
|
||||
record.LastUpdatedUnix = GetNowUnixSeconds();
|
||||
if (cacheReadyAtRequest)
|
||||
{
|
||||
MarkImmediateHit(adType, normalizedScenario);
|
||||
MarkImmediateHit(adType, normalizedScenario, slotId);
|
||||
}
|
||||
else
|
||||
{
|
||||
MarkCacheExpiredIfStale(adType);
|
||||
MarkCacheExpiredIfStale(adType, slotId);
|
||||
}
|
||||
|
||||
SaveStates();
|
||||
}
|
||||
|
||||
public static void OnLoadRequested(AD_Type adType, string scenario)
|
||||
public static void OnLoadRequested(AD_Type adType, string scenario, string slotId = null)
|
||||
{
|
||||
if (!_initialized || !_enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
PrepareSmartLoadRequest(adType, scenario);
|
||||
PrepareSmartLoadRequest(adType, scenario, slotId);
|
||||
}
|
||||
|
||||
public static void OnLoadStarted(AD_Type adType, string scenario)
|
||||
public static void OnLoadStarted(AD_Type adType, string scenario, string slotId = null)
|
||||
{
|
||||
if (!_initialized || !_enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BeginLoadRequest(adType, scenario);
|
||||
BeginLoadRequest(adType, scenario, slotId);
|
||||
SaveStates();
|
||||
}
|
||||
|
||||
public static void OnLoadResult(AD_Type adType, string scenario, bool success)
|
||||
public static void OnLoadResult(AD_Type adType, string scenario, bool success, string slotId = null)
|
||||
{
|
||||
if (!_initialized || !_enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CompleteLoadRequest(adType, scenario, success);
|
||||
CompleteLoadRequest(adType, scenario, success, slotId);
|
||||
SaveStates();
|
||||
}
|
||||
|
||||
public static void OnShowStart(AD_Type adType, string scenario)
|
||||
public static void OnShowStart(AD_Type adType, string scenario, string slotId = null)
|
||||
{
|
||||
if (!_initialized || !_enabled)
|
||||
{
|
||||
@@ -204,11 +204,11 @@ public static class TapadnSmartLoadOrchestrator
|
||||
var record = GetOrCreateState(adType, NormalizeScenario(scenario));
|
||||
record.ShowStartCount = Math.Max(0, record.ShowStartCount) + 1;
|
||||
record.LastUpdatedUnix = GetNowUnixSeconds();
|
||||
MarkCacheConsumed(adType, scenario);
|
||||
MarkCacheConsumed(adType, scenario, slotId);
|
||||
SaveStates();
|
||||
}
|
||||
|
||||
public static void OnShowError(AD_Type adType, string scenario)
|
||||
public static void OnShowError(AD_Type adType, string scenario, string slotId = null)
|
||||
{
|
||||
if (!_initialized || !_enabled)
|
||||
{
|
||||
@@ -218,11 +218,11 @@ public static class TapadnSmartLoadOrchestrator
|
||||
var record = GetOrCreateState(adType, NormalizeScenario(scenario));
|
||||
record.ShowFailureCount = Math.Max(0, record.ShowFailureCount) + 1;
|
||||
record.LastUpdatedUnix = GetNowUnixSeconds();
|
||||
MarkCacheShowFailed(adType, scenario);
|
||||
MarkCacheShowFailed(adType, scenario, slotId);
|
||||
SaveStates();
|
||||
}
|
||||
|
||||
private static void TryPreload(AD_Type adType, string scenario)
|
||||
private static void TryPreload(AD_Type adType, string scenario, string slotId)
|
||||
{
|
||||
if (!_initialized || !_enabled)
|
||||
{
|
||||
@@ -257,11 +257,11 @@ public static class TapadnSmartLoadOrchestrator
|
||||
return;
|
||||
}
|
||||
|
||||
MarkCacheExpiredIfStale(adType);
|
||||
OnLoadRequested(adType, scenario);
|
||||
MarkCacheExpiredIfStale(adType, slotId);
|
||||
OnLoadRequested(adType, scenario, slotId);
|
||||
ADManager.Instance.LoadAD(adType);
|
||||
var smartLoadStarted = HasPendingSmartLoadForScene(adType, scenario);
|
||||
ClearPreparedLoadIfNotStarted(adType);
|
||||
var smartLoadStarted = HasPendingSmartLoadForScene(adType, scenario, slotId);
|
||||
ClearPreparedLoadIfNotStarted(adType, slotId);
|
||||
if (!smartLoadStarted)
|
||||
{
|
||||
return;
|
||||
@@ -302,9 +302,9 @@ public static class TapadnSmartLoadOrchestrator
|
||||
return Mathf.Lerp(policy.BaseProbability, observedRate, trust);
|
||||
}
|
||||
|
||||
private static void PrepareSmartLoadRequest(AD_Type adType, string scenario)
|
||||
private static void PrepareSmartLoadRequest(AD_Type adType, string scenario, string slotId)
|
||||
{
|
||||
var state = GetOrCreateCacheState(adType);
|
||||
var state = GetOrCreateCacheState(adType, slotId);
|
||||
if (state.PendingSmartLoad)
|
||||
{
|
||||
return;
|
||||
@@ -316,9 +316,9 @@ public static class TapadnSmartLoadOrchestrator
|
||||
state.PreparedRequestUnix = GetNowUnixSeconds();
|
||||
}
|
||||
|
||||
private static void BeginLoadRequest(AD_Type adType, string scenario)
|
||||
private static void BeginLoadRequest(AD_Type adType, string scenario, string slotId)
|
||||
{
|
||||
var state = GetOrCreateCacheState(adType);
|
||||
var state = GetOrCreateCacheState(adType, slotId);
|
||||
var now = GetNowUnixSeconds();
|
||||
if (state.PreparedSmartLoad)
|
||||
{
|
||||
@@ -346,9 +346,9 @@ public static class TapadnSmartLoadOrchestrator
|
||||
state.PreparedRequestUnix = 0;
|
||||
}
|
||||
|
||||
private static void ClearPreparedLoadIfNotStarted(AD_Type adType)
|
||||
private static void ClearPreparedLoadIfNotStarted(AD_Type adType, string slotId)
|
||||
{
|
||||
var state = GetOrCreateCacheState(adType);
|
||||
var state = GetOrCreateCacheState(adType, slotId);
|
||||
if (state.PendingSmartLoad)
|
||||
{
|
||||
return;
|
||||
@@ -360,16 +360,16 @@ public static class TapadnSmartLoadOrchestrator
|
||||
state.PreparedRequestUnix = 0;
|
||||
}
|
||||
|
||||
private static bool HasPendingSmartLoadForScene(AD_Type adType, string scenario)
|
||||
private static bool HasPendingSmartLoadForScene(AD_Type adType, string scenario, string slotId)
|
||||
{
|
||||
var state = GetOrCreateCacheState(adType);
|
||||
var state = GetOrCreateCacheState(adType, slotId);
|
||||
return state.PendingSmartLoad &&
|
||||
string.Equals(NormalizeScenario(state.PendingOriginScene), NormalizeScenario(scenario), StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static void CompleteLoadRequest(AD_Type adType, string scenario, bool success)
|
||||
private static void CompleteLoadRequest(AD_Type adType, string scenario, bool success, string slotId)
|
||||
{
|
||||
var cacheState = GetOrCreateCacheState(adType);
|
||||
var cacheState = GetOrCreateCacheState(adType, slotId);
|
||||
var normalizedScenario = NormalizeScenario(scenario);
|
||||
var originScene = cacheState.PendingSmartLoad ? NormalizeScenario(cacheState.PendingOriginScene) : normalizedScenario;
|
||||
var originRecord = GetOrCreateState(adType, originScene);
|
||||
@@ -408,23 +408,23 @@ public static class TapadnSmartLoadOrchestrator
|
||||
cacheState.PendingRequestUnix = 0;
|
||||
}
|
||||
|
||||
private static void MarkImmediateHit(AD_Type adType, string scenario)
|
||||
private static void MarkImmediateHit(AD_Type adType, string scenario, string slotId)
|
||||
{
|
||||
var consumedScene = NormalizeScenario(scenario);
|
||||
var currentSceneRecord = GetOrCreateState(adType, consumedScene);
|
||||
currentSceneRecord.ImmediateHitCount = Math.Max(0, currentSceneRecord.ImmediateHitCount) + 1;
|
||||
currentSceneRecord.LastUpdatedUnix = GetNowUnixSeconds();
|
||||
|
||||
var cacheState = GetOrCreateCacheState(adType);
|
||||
var cacheState = GetOrCreateCacheState(adType, slotId);
|
||||
if (!cacheState.HasReadyCache)
|
||||
{
|
||||
currentSceneRecord.UnattributedCacheHitCount = Math.Max(0, currentSceneRecord.UnattributedCacheHitCount) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private static void MarkCacheConsumed(AD_Type adType, string scenario)
|
||||
private static void MarkCacheConsumed(AD_Type adType, string scenario, string slotId)
|
||||
{
|
||||
var cacheState = GetOrCreateCacheState(adType);
|
||||
var cacheState = GetOrCreateCacheState(adType, slotId);
|
||||
if (!cacheState.HasReadyCache || cacheState.Consumed)
|
||||
{
|
||||
return;
|
||||
@@ -458,9 +458,9 @@ public static class TapadnSmartLoadOrchestrator
|
||||
ClearReadyCache(cacheState);
|
||||
}
|
||||
|
||||
private static void MarkCacheShowFailed(AD_Type adType, string scenario)
|
||||
private static void MarkCacheShowFailed(AD_Type adType, string scenario, string slotId)
|
||||
{
|
||||
var cacheState = GetOrCreateCacheState(adType);
|
||||
var cacheState = GetOrCreateCacheState(adType, slotId);
|
||||
if (!cacheState.HasReadyCache)
|
||||
{
|
||||
return;
|
||||
@@ -479,9 +479,9 @@ public static class TapadnSmartLoadOrchestrator
|
||||
ClearReadyCache(cacheState);
|
||||
}
|
||||
|
||||
private static void MarkCacheExpiredIfStale(AD_Type adType)
|
||||
private static void MarkCacheExpiredIfStale(AD_Type adType, string slotId)
|
||||
{
|
||||
var cacheState = GetOrCreateCacheState(adType);
|
||||
var cacheState = GetOrCreateCacheState(adType, slotId);
|
||||
if (!cacheState.HasReadyCache)
|
||||
{
|
||||
return;
|
||||
@@ -502,9 +502,9 @@ public static class TapadnSmartLoadOrchestrator
|
||||
ClearReadyCache(cacheState);
|
||||
}
|
||||
|
||||
private static TapadnSmartLoadCacheState GetOrCreateCacheState(AD_Type adType)
|
||||
private static TapadnSmartLoadCacheState GetOrCreateCacheState(AD_Type adType, string slotId)
|
||||
{
|
||||
var key = (int)adType;
|
||||
var key = ComposeCacheKey(adType, slotId);
|
||||
if (_cacheStates.TryGetValue(key, out var state) && state != null)
|
||||
{
|
||||
return state;
|
||||
@@ -879,6 +879,16 @@ public static class TapadnSmartLoadOrchestrator
|
||||
return ((int)adType) + "|" + NormalizeScenario(scenario);
|
||||
}
|
||||
|
||||
private static string ComposeCacheKey(AD_Type adType, string slotId)
|
||||
{
|
||||
return ((int)adType) + "|" + NormalizeSlotId(slotId);
|
||||
}
|
||||
|
||||
private static string NormalizeSlotId(string slotId)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(slotId) ? "__default_slot__" : slotId.Trim();
|
||||
}
|
||||
|
||||
private static string NormalizeScenario(string scenario)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(scenario))
|
||||
|
||||
@@ -56,12 +56,12 @@ public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListene
|
||||
}
|
||||
|
||||
curState = 1;
|
||||
TapadnSmartLoadOrchestrator.OnLoadStarted(AD_Type.Splash, AdScene);
|
||||
TapadnSmartLoadOrchestrator.OnLoadStarted(AD_Type.Splash, AdScene, Key);
|
||||
_adNative.LoadSplashAd(
|
||||
TapadnAdRequestFactory.BuildSplash(Key, TapadnAdController.CurrentOptions),
|
||||
ad =>
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.Splash, AdScene, true);
|
||||
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.Splash, AdScene, true, Key);
|
||||
_loadedAd?.Destroy();
|
||||
_loadedAd = ad;
|
||||
_loadedAd.Shown += OnManualShown;
|
||||
@@ -73,7 +73,7 @@ public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListene
|
||||
},
|
||||
error =>
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.Splash, AdScene, false);
|
||||
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.Splash, AdScene, false, Key);
|
||||
curState = 0;
|
||||
Debug.LogError($"[TapADN] Splash load failed. code={error.Code}, message={error.Message}");
|
||||
});
|
||||
@@ -106,7 +106,7 @@ public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListene
|
||||
}
|
||||
|
||||
_showSettled = true;
|
||||
TapadnSmartLoadOrchestrator.OnShowError(AD_Type.Splash, AdScene);
|
||||
TapadnSmartLoadOrchestrator.OnShowError(AD_Type.Splash, AdScene, Key);
|
||||
curState = 0;
|
||||
Debug.LogError($"[TapADN] Splash show failed. code={error?.Code}, message={error?.Message}");
|
||||
adListener.OnShowError();
|
||||
@@ -114,7 +114,7 @@ public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListene
|
||||
|
||||
public void OnAdShow()
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnShowStart(AD_Type.Splash, AdScene);
|
||||
TapadnSmartLoadOrchestrator.OnShowStart(AD_Type.Splash, AdScene, Key);
|
||||
NotifyShowStarted();
|
||||
}
|
||||
|
||||
@@ -136,12 +136,13 @@ public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListene
|
||||
|
||||
public override void OnPlayRequestStarted()
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnPlayRequestStarted(AD_Type.Splash, AdScene, !UseAutoLoad() && IsReadly());
|
||||
TapadnSmartLoadOrchestrator.OnPlayRequestStarted(AD_Type.Splash, AdScene, !UseAutoLoad() && IsReadly(), Key);
|
||||
}
|
||||
|
||||
public override void EnterAdScenario(string scenario)
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnEnterAdScenario(AD_Type.Splash, scenario, Key);
|
||||
AdScene = string.IsNullOrWhiteSpace(scenario) ? "__default__" : scenario.Trim();
|
||||
TapadnSmartLoadOrchestrator.OnEnterAdScenario(AD_Type.Splash, AdScene, Key);
|
||||
}
|
||||
|
||||
private bool UseAutoLoad()
|
||||
@@ -151,7 +152,7 @@ public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListene
|
||||
|
||||
private void OnManualShown()
|
||||
{
|
||||
TapadnSmartLoadOrchestrator.OnShowStart(AD_Type.Splash, AdScene);
|
||||
TapadnSmartLoadOrchestrator.OnShowStart(AD_Type.Splash, AdScene, Key);
|
||||
NotifyShowStarted();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "com.commercialization.tapadn",
|
||||
"displayName": "Commercialization.tapadn",
|
||||
"description": "TapADN / Dirichlet mediation implementation for CC-Framework.Commercialization.",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"unity": "2022.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
|
||||
52
README.md
52
README.md
@@ -9,7 +9,7 @@
|
||||
```json
|
||||
{
|
||||
"com.foldcc.cc-framework.commercialization": "http://private.lightyears.ltd:18650/foldcc/CC-Framework.Commercialization.git#1.0.15",
|
||||
"com.commercialization.tapadn": "http://private.lightyears.ltd:18650/foldcc/Commercialization.tapadn.git#1.0.3"
|
||||
"com.commercialization.tapadn": "http://private.lightyears.ltd:18650/foldcc/Commercialization.tapadn.git?path=/Assets#1.0.4"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -73,6 +73,10 @@ ADManager.Instance.Init(callback, userId, adConfig, new TapadnAdController());
|
||||
* `tapadn.rewarded_max_load_attempts`
|
||||
* `tapadn.rewarded_load_retry_delay_ms`
|
||||
* `tapadn.rewarded_show_timeout_ms`
|
||||
* `tapadn.rewarded_scene_slot.<scene_id>`(激励视频场景广告位映射,值为对应 SpaceId)
|
||||
* `tapadn.rewarded_scene_slots`(激励视频场景广告位批量映射,格式 `scene_a=10001,scene_b=10002`)
|
||||
* `tapadn.rewarded_scene_slots_json`(激励视频场景广告位 JSON,格式见下方)
|
||||
* `tapadn.rewarded_cache_max_age_seconds`(可选本地缓存年龄上限;默认 `600` 秒,设为 `0` 表示只使用 SDK `IsValid` 判断)
|
||||
* `tapadn.interstitial_auto_load`
|
||||
* `tapadn.interstitial_prewarm_on_init`
|
||||
* `tapadn.interstitial_max_load_attempts`
|
||||
@@ -92,6 +96,52 @@ ADManager.Instance.Init(callback, userId, adConfig, new TapadnAdController());
|
||||
|
||||
默认激励、插屏、开屏都使用手动 load/show;如无特殊策略验证需求,不建议开启 auto-ad。若要做 auto-ad AB 测试,再将对应 `*_auto_load` 设为 `true`。
|
||||
|
||||
### 激励视频场景广告位
|
||||
|
||||
激励视频支持按游戏场景路由不同 TapADN SpaceId。项目层继续调用 `ADManager.EnterAdScenario(AD_Type.AwardVideo, sceneId)` 和 `ADManager.AsyncPlayAD(AD_Type.AwardVideo, sceneId, callback)`;TapADN adapter 会按 `sceneId` 查表:
|
||||
|
||||
* 命中 `tapadn.rewarded_scene_slot.<scene_id>` 或批量配置时,使用该场景 SpaceId。
|
||||
* 未传场景、场景为空、场景未配置、配置的 SpaceId 非法时,回退到 `BaseAwardAdKeyValue.value` 默认激励视频广告位。
|
||||
* 手动 load/show 模式下,缓存按 SpaceId 隔离;A 场景加载的激励视频不会被 B 场景误认为 ready。
|
||||
|
||||
单项配置示例:
|
||||
|
||||
```csharp
|
||||
adConfig.CommonKeyValues.Add(new AdKeyValue
|
||||
{
|
||||
key = "tapadn.rewarded_scene_slot.level_clear",
|
||||
value = "200101"
|
||||
});
|
||||
```
|
||||
|
||||
批量字符串配置示例:
|
||||
|
||||
```csharp
|
||||
adConfig.CommonKeyValues.Add(new AdKeyValue
|
||||
{
|
||||
key = "tapadn.rewarded_scene_slots",
|
||||
value = "level_clear=200101,daily_bonus=200102"
|
||||
});
|
||||
```
|
||||
|
||||
JSON 配置示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"Mappings": [
|
||||
{ "Scene": "level_clear", "SlotId": "200101" },
|
||||
{ "Scene": "daily_bonus", "SlotId": "200102" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
生命周期策略按官方文档保持保守:
|
||||
|
||||
* `DirichletAdNative` 仍由每个 TapADN player 统一持有,不在每个场景重复创建。
|
||||
* 手动加载返回的 `DirichletRewardVideoAd` 按 SpaceId 缓存;展示关闭、展示失败、SDK `IsValid == false` 或超过 `tapadn.rewarded_cache_max_age_seconds` 后销毁。
|
||||
* 官方文档没有给出固定过期秒数;本模块默认 10 分钟未消费主动销毁,同时每次 ready/show 前仍调用 SDK `IsValid`。
|
||||
* Android auto-ad 仍交给官方 `ShowRewardVideoAutoAd` / `PreLoad` 的 native 缓存管理;iOS/Editor fallback 仍是 load 成功后立即 show,不承诺 native 缓存语义。
|
||||
|
||||
### 智能预加载(实验)
|
||||
|
||||
默认会按“场景进入次数 + 场景播放请求次数”维护一个小样本统计:
|
||||
|
||||
Reference in New Issue
Block a user