fix: support legacy TapADN rewarded scene slots

This commit is contained in:
2026-06-17 18:15:02 +08:00
parent 9c99482b2d
commit 3f527fa94d
6 changed files with 120 additions and 7 deletions

View File

@@ -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<string, string> 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<string, string> 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<string, string> add)
{
if (string.IsNullOrWhiteSpace(value) || add == null)