You've already forked Commercialization.tapadn
release: 1.0.4
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user