From 286799142bb30b6922849955985acf720f87c1c4 Mon Sep 17 00:00:00 2001 From: CORE-FOLDCCCore <1813547935@qq.com> Date: Wed, 17 Jun 2026 18:15:02 +0800 Subject: [PATCH] fix: support legacy TapADN rewarded scene slots --- CHANGELOG.md | 7 +++ .../Runtime/TapadnIAAAdDebugSampleGui.cs | 27 +++++++++++ .../Runtime/Scripts/TapadnAwardVideoPlayer.cs | 30 ++++++++++-- .../Scripts/TapadnControllerOptions.cs | 48 +++++++++++++++++++ package.json | 2 +- 5 files changed, 108 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 359a215..c7c39f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [1.0.6] + +### 修复 + +* 兼容 `CommonKeyValues` 中直接使用业务场景名作为 key、SpaceId 作为 value 的激励视频广告位配置,避免只识别 `tapadn.rewarded_scene_slot.` 时回退到默认激励广告位。 +* 激励视频进入场景、加载和播放请求会输出当前解析到的 SpaceId 及来源,便于 Editor Console 和样例调试面板确认实际使用的广告位。 + # [1.0.5] ### 调整 diff --git a/Samples~/IAAAdDebugSample/Runtime/TapadnIAAAdDebugSampleGui.cs b/Samples~/IAAAdDebugSample/Runtime/TapadnIAAAdDebugSampleGui.cs index 4920d82..abfb5da 100644 --- a/Samples~/IAAAdDebugSample/Runtime/TapadnIAAAdDebugSampleGui.cs +++ b/Samples~/IAAAdDebugSample/Runtime/TapadnIAAAdDebugSampleGui.cs @@ -162,6 +162,7 @@ public sealed class TapadnIAAAdDebugSampleGui : MonoBehaviour GUILayout.Label($"Last EventLog: {_lastEventLog}", _textStyle); GUILayout.Label($"Last SDK Version: {DisplayValue(TapadnAdController.LastSdkVersion)}", _textStyle); GUILayout.Label($"Last Init Error: {DisplayValue(TapadnAdController.LastInitError)}", _textStyle); + GUILayout.Label($"Rewarded Selected SpaceId: {GetResolvedRewardedSlotForDisplay(rewardedScenario)}", _textStyle); } else { @@ -250,6 +251,7 @@ public sealed class TapadnIAAAdDebugSampleGui : MonoBehaviour if (EnsureInitialized(label)) { + LogRewardedResolvedSlot(adType, scenario, "Enter scenario"); ADManager.Instance.EnterAdScenario(adType, scenario); AppendLog($"Enter scenario requested. type={adType}, scenario={scenario}"); } @@ -278,6 +280,7 @@ public sealed class TapadnIAAAdDebugSampleGui : MonoBehaviour if (EnsureInitialized(label)) { + LogRewardedResolvedSlot(adType, scenario, "AsyncPlayAD"); ADManager.Instance.AsyncPlayAD(adType, scenario, result => { AppendLog($"{adType} callback: {result}"); @@ -424,6 +427,30 @@ public sealed class TapadnIAAAdDebugSampleGui : MonoBehaviour } AppendLog($"Options => mediaId={options.MediaId}, channel={options.Channel}, sub={options.SubChannel}, debug={options.Debug}, rewardAuto={options.RewardedAutoLoad}, interAuto={options.InterstitialAutoLoad}, splashAuto={options.SplashAutoLoad}"); + AppendLog($"Rewarded selected slot => {GetResolvedRewardedSlotForDisplay(rewardedScenario)}, configuredSceneSlots={options.RewardedSceneSlotIds?.Count ?? 0}"); + } + + private void LogRewardedResolvedSlot(AD_Type adType, string scenario, string actionName) + { + if (adType != AD_Type.AwardVideo) + { + return; + } + + AppendLog($"{actionName} rewarded slot => {GetResolvedRewardedSlotForDisplay(scenario)}"); + } + + private string GetResolvedRewardedSlotForDisplay(string scenario) + { + var defaultSlotId = adConfig?.BaseAwardAdKeyValue?.value; + var options = TapadnAdController.CurrentOptions; + if (options == null) + { + return $"{DisplayValue(defaultSlotId)} (source=default, scenario={DisplayValue(scenario)})"; + } + + var slotId = options.ResolveRewardedSlotId(defaultSlotId, scenario, out var mapped); + return $"{DisplayValue(slotId)} (source={(mapped ? "scene" : "default")}, scenario={DisplayValue(scenario)})"; } private void OnRewardedBefore(string placementId, string scenario) diff --git a/Tapadn_Adapter/Runtime/Scripts/TapadnAwardVideoPlayer.cs b/Tapadn_Adapter/Runtime/Scripts/TapadnAwardVideoPlayer.cs index 7e986c9..25e9ac4 100644 --- a/Tapadn_Adapter/Runtime/Scripts/TapadnAwardVideoPlayer.cs +++ b/Tapadn_Adapter/Runtime/Scripts/TapadnAwardVideoPlayer.cs @@ -62,7 +62,8 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto public override void LoadAD() { - var slotId = ResolveCurrentSlotId(); + var slotId = ResolveCurrentSlotId(out var mapped); + Debug.Log($"[TapADN] Rewarded load requested. scene={NormalizeScenario(AdScene)}, slot={slotId}, source={GetSlotSource(mapped)}, auto={UseAutoLoad()}"); if (!TapadnAdRequestFactory.TryParseSlotId(slotId, out _)) { Debug.LogError($"[TapADN] Invalid rewarded slot id: {slotId}"); @@ -128,9 +129,10 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto _showSettled = false; _rewardCloseSettleHandler?.Kill(); _rewardCloseSettleHandler = null; - _activeSlotId = ResolveCurrentSlotId(); + _activeSlotId = ResolveCurrentSlotId(out var mapped); Key = _activeSlotId; curState = 0; + Debug.Log($"[TapADN] Rewarded show requested. scene={NormalizeScenario(AdScene)}, slot={_activeSlotId}, source={GetSlotSource(mapped)}, auto={UseAutoLoad()}"); if (UseAutoLoad()) { @@ -203,25 +205,43 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto public override void OnPlayRequestStarted() { - var slotId = ResolveCurrentSlotId(); + var slotId = ResolveCurrentSlotId(out var mapped); Key = slotId; + Debug.Log($"[TapADN] Rewarded play request. scene={NormalizeScenario(AdScene)}, slot={slotId}, source={GetSlotSource(mapped)}, auto={UseAutoLoad()}"); TapadnSmartLoadOrchestrator.OnPlayRequestStarted(AD_Type.AwardVideo, AdScene, !UseAutoLoad() && IsReadly(), slotId); } public override void EnterAdScenario(string scenario) { AdScene = NormalizeScenario(scenario); - var slotId = ResolveCurrentSlotId(); + var slotId = ResolveCurrentSlotId(out var mapped); Key = slotId; + Debug.Log($"[TapADN] Rewarded enter scene. scene={AdScene}, slot={slotId}, source={GetSlotSource(mapped)}"); TapadnSmartLoadOrchestrator.OnEnterAdScenario(AD_Type.AwardVideo, AdScene, slotId); } private string ResolveCurrentSlotId() { - var slotId = TapadnAdController.CurrentOptions?.ResolveRewardedSlotId(_defaultSlotId, AdScene) ?? _defaultSlotId; + return ResolveCurrentSlotId(out _); + } + + private string ResolveCurrentSlotId(out bool mapped) + { + if (TapadnAdController.CurrentOptions == null) + { + mapped = false; + return string.IsNullOrWhiteSpace(_defaultSlotId) ? _defaultSlotId : _defaultSlotId.Trim(); + } + + var slotId = TapadnAdController.CurrentOptions.ResolveRewardedSlotId(_defaultSlotId, AdScene, out mapped); return string.IsNullOrWhiteSpace(slotId) ? _defaultSlotId : slotId.Trim(); } + private static string GetSlotSource(bool mapped) + { + return mapped ? "scene" : "default"; + } + private bool UseAutoLoad() { return TapadnAdController.CurrentOptions?.RewardedAutoLoad ?? true; diff --git a/Tapadn_Adapter/Runtime/Scripts/TapadnControllerOptions.cs b/Tapadn_Adapter/Runtime/Scripts/TapadnControllerOptions.cs index 7bd488c..41b1d6e 100644 --- a/Tapadn_Adapter/Runtime/Scripts/TapadnControllerOptions.cs +++ b/Tapadn_Adapter/Runtime/Scripts/TapadnControllerOptions.cs @@ -9,6 +9,8 @@ using UnityEngine; public sealed class TapadnControllerOptions { + private const string TapadnKeyPrefix = "tapadn."; + public const string MediaNameKey = "tapadn.media_name"; public const string MediaIdKey = "tapadn.media_id"; public const string MediaKeyKey = "tapadn.media_key"; @@ -300,20 +302,29 @@ public sealed class TapadnControllerOptions } public string ResolveRewardedSlotId(string defaultSlotId, string scenario) + { + return ResolveRewardedSlotId(defaultSlotId, scenario, out _); + } + + public string ResolveRewardedSlotId(string defaultSlotId, string scenario, out bool mapped) { var normalizedScenario = NormalizeScenario(scenario); if (RewardedSceneSlotIds != null && RewardedSceneSlotIds.TryGetValue(normalizedScenario, out var mappedSlotId) && TapadnAdRequestFactory.TryParseSlotId(mappedSlotId, out _)) { + mapped = true; return mappedSlotId; } + mapped = false; return defaultSlotId; } private void ApplyRewardedSceneSlots(IDictionary map) { + ApplyLegacyRewardedSceneSlots(map); + foreach (var entry in map) { if (entry.Key == null || !entry.Key.StartsWith(RewardedSceneSlotPrefix, StringComparison.OrdinalIgnoreCase)) @@ -329,6 +340,19 @@ public sealed class TapadnControllerOptions ParseSceneSlotJson(GetString(map, RewardedSceneSlotsJsonKey), AddRewardedSceneSlot); } + private void ApplyLegacyRewardedSceneSlots(IDictionary map) + { + foreach (var entry in map) + { + if (!IsLegacyRewardedSceneSlotEntry(entry.Key, entry.Value)) + { + continue; + } + + AddRewardedSceneSlot(entry.Key, entry.Value); + } + } + private void AddRewardedSceneSlot(string scene, string slotId) { scene = NormalizeScenario(scene); @@ -341,6 +365,30 @@ public sealed class TapadnControllerOptions RewardedSceneSlotIds[scene] = slotId.Trim(); } + private static bool IsLegacyRewardedSceneSlotEntry(string key, string value) + { + var normalizedKey = key?.Trim(); + if (string.IsNullOrWhiteSpace(normalizedKey) || + string.IsNullOrWhiteSpace(value) || + normalizedKey.StartsWith(TapadnKeyPrefix, StringComparison.OrdinalIgnoreCase)) + { + return false; + } + + switch (normalizedKey.ToLowerInvariant()) + { + case "media_id": + case "media_name": + case "media_key": + case "channel": + case "sub_channel": + case "debug": + return false; + } + + return TapadnAdRequestFactory.TryParseSlotId(value.Trim(), out _); + } + private static void ParseSceneSlotPairs(string value, Action add) { if (string.IsNullOrWhiteSpace(value) || add == null) diff --git a/package.json b/package.json index dcbf331..c8edbf3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.commercialization.tapadn", "displayName": "Commercialization.tapadn", "description": "TapADN / Dirichlet mediation implementation for CC-Framework.Commercialization.", - "version": "1.0.5", + "version": "1.0.6", "unity": "2022.3", "license": "MIT", "repository": {