You've already forked Commercialization.tapadn
fix: support legacy TapADN rewarded scene slots
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user