You've already forked Commercialization.topon
release: 1.4.2
This commit is contained in:
@@ -21,9 +21,16 @@ public class ADListenerAggregator
|
||||
client.onAdClickEvent += this.onRewardedVideoAdPlayClicked;
|
||||
client.onAdLoadEvent += this.onRewardedVideoAdLoaded;
|
||||
client.onAdLoadFailureEvent += this.onRewardedVideoAdLoadFail;
|
||||
client.onAdVideoStartEvent += this.onRewardedVideoAdPlayStart;
|
||||
client.onAdVideoEndEvent += this.onRewardedVideoAdPlayEnd;
|
||||
client.onAdVideoCloseEvent += this.onRewardedVideoAdPlayClosed;
|
||||
client.onAdVideoFailureEvent += this.onRewardedVideoAdPlayFail;
|
||||
client.onAdSourceAttemptEvent += this.startLoadingRewardedAdSource;
|
||||
client.onAdSourceFilledEvent += this.finishLoadingRewardedAdSource;
|
||||
client.onAdSourceLoadFailureEvent += this.failToLoadRewardedAdSource;
|
||||
client.onAdSourceBiddingAttemptEvent += this.startBiddingRewardedAdSource;
|
||||
client.onAdSourceBiddingFilledEvent += this.finishBiddingRewardedAdSource;
|
||||
client.onAdSourceBiddingFailureEvent += this.failBiddingRewardedAdSource;
|
||||
}
|
||||
|
||||
this._awardVideoListener = listener;
|
||||
@@ -62,6 +69,15 @@ public class ADListenerAggregator
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* The Ad play start (note: for Android, all callback methods are not in the main thread of Unity)
|
||||
*/
|
||||
void onRewardedVideoAdPlayStart(object sender, ATAdEventArgs callbackInfo)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._awardVideoListener?.onRewardedVideoAdPlayStart(callbackInfo.placementId,
|
||||
callbackInfo.callbackInfo));
|
||||
}
|
||||
|
||||
/***
|
||||
* The Ad play end (note: for Android, all callback methods are not in the main thread of Unity)
|
||||
*/
|
||||
@@ -110,6 +126,42 @@ public class ADListenerAggregator
|
||||
callbackInfo.callbackInfo));
|
||||
}
|
||||
|
||||
void startLoadingRewardedAdSource(object sender, ATAdEventArgs callbackInfo)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._awardVideoListener?.startLoadingADSource(callbackInfo.placementId,
|
||||
callbackInfo.callbackInfo));
|
||||
}
|
||||
|
||||
void finishLoadingRewardedAdSource(object sender, ATAdEventArgs callbackInfo)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._awardVideoListener?.finishLoadingADSource(callbackInfo.placementId,
|
||||
callbackInfo.callbackInfo));
|
||||
}
|
||||
|
||||
void failToLoadRewardedAdSource(object sender, ATAdErrorEventArgs callbackInfo)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._awardVideoListener?.failToLoadADSource(callbackInfo.placementId,
|
||||
callbackInfo.callbackInfo, callbackInfo.errorCode, callbackInfo.errorMessage));
|
||||
}
|
||||
|
||||
void startBiddingRewardedAdSource(object sender, ATAdEventArgs callbackInfo)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._awardVideoListener?.startBiddingADSource(callbackInfo.placementId,
|
||||
callbackInfo.callbackInfo));
|
||||
}
|
||||
|
||||
void finishBiddingRewardedAdSource(object sender, ATAdEventArgs callbackInfo)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._awardVideoListener?.finishBiddingADSource(callbackInfo.placementId,
|
||||
callbackInfo.callbackInfo));
|
||||
}
|
||||
|
||||
void failBiddingRewardedAdSource(object sender, ATAdErrorEventArgs callbackInfo)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._awardVideoListener?.failBiddingADSource(callbackInfo.placementId,
|
||||
callbackInfo.callbackInfo, callbackInfo.errorCode, callbackInfo.errorMessage));
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 加载广告成功(注意:对于Android来说,所有回调方法均不在Unity的主线程)
|
||||
|
||||
@@ -103,6 +103,19 @@ public class ToponAdController : IAdController
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.InitCustomMap != null && options.InitCustomMap.Count > 0)
|
||||
{
|
||||
ATSDKAPI.initCustomMap(options.InitCustomMap);
|
||||
}
|
||||
|
||||
var rewardedPlacementId = _adConfig?.BaseAwardAdKeyValue?.value;
|
||||
if (!string.IsNullOrWhiteSpace(rewardedPlacementId) &&
|
||||
options.RewardedCustomData != null &&
|
||||
options.RewardedCustomData.Count > 0)
|
||||
{
|
||||
ATSDKAPI.setCustomDataForPlacementID(options.RewardedCustomData, rewardedPlacementId);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(options.Channel))
|
||||
{
|
||||
ATSDKAPI.setChannel(options.Channel);
|
||||
|
||||
@@ -17,6 +17,8 @@ public sealed class ToponControllerOptions
|
||||
public const string ExcludeBundleIdsKey = "topon.exclude_bundle_ids";
|
||||
public const string RewardedExcludeAdSourceIdsKey = "topon.rewarded_exclude_ad_source_ids";
|
||||
public const string QueryAreaOnInitKey = "topon.query_area_on_init";
|
||||
public const string InitCustomMapKey = "topon.custom_map";
|
||||
public const string RewardedCustomDataKey = "topon.rewarded_custom_data";
|
||||
|
||||
public string Channel { get; set; }
|
||||
public string SubChannel { get; set; }
|
||||
@@ -28,6 +30,8 @@ public sealed class ToponControllerOptions
|
||||
public string[] ExcludeBundleIds { get; set; }
|
||||
public string[] RewardedExcludeAdSourceIds { get; set; }
|
||||
public bool QueryAreaOnInit { get; set; }
|
||||
public Dictionary<string, string> InitCustomMap { get; set; }
|
||||
public Dictionary<string, string> RewardedCustomData { get; set; }
|
||||
public Action<string> OnAreaReceived { get; set; }
|
||||
public Action<string> OnAreaError { get; set; }
|
||||
|
||||
@@ -87,6 +91,8 @@ public sealed class ToponControllerOptions
|
||||
ExcludeBundleIds = GetStringArray(map, ExcludeBundleIdsKey) ?? ExcludeBundleIds;
|
||||
RewardedExcludeAdSourceIds = GetStringArray(map, RewardedExcludeAdSourceIdsKey) ?? RewardedExcludeAdSourceIds;
|
||||
QueryAreaOnInit = GetBool(map, QueryAreaOnInitKey) ?? QueryAreaOnInit;
|
||||
InitCustomMap = MergeMaps(InitCustomMap, GetPrefixedMap(map, InitCustomMapKey + "."));
|
||||
RewardedCustomData = MergeMaps(RewardedCustomData, GetPrefixedMap(map, RewardedCustomDataKey + "."));
|
||||
}
|
||||
|
||||
private void ApplyLegacyArgs(object[] args)
|
||||
@@ -124,6 +130,8 @@ public sealed class ToponControllerOptions
|
||||
ExcludeBundleIds = explicitOptions.ExcludeBundleIds ?? ExcludeBundleIds;
|
||||
RewardedExcludeAdSourceIds = explicitOptions.RewardedExcludeAdSourceIds ?? RewardedExcludeAdSourceIds;
|
||||
QueryAreaOnInit = explicitOptions.QueryAreaOnInit || QueryAreaOnInit;
|
||||
InitCustomMap = MergeMaps(InitCustomMap, explicitOptions.InitCustomMap);
|
||||
RewardedCustomData = MergeMaps(RewardedCustomData, explicitOptions.RewardedCustomData);
|
||||
OnAreaReceived = explicitOptions.OnAreaReceived ?? OnAreaReceived;
|
||||
OnAreaError = explicitOptions.OnAreaError ?? OnAreaError;
|
||||
}
|
||||
@@ -143,7 +151,23 @@ public sealed class ToponControllerOptions
|
||||
continue;
|
||||
}
|
||||
|
||||
map[entry.Key.ToString()] = ConvertDictionaryValue(entry.Value);
|
||||
var key = entry.Key.ToString();
|
||||
if (entry.Value is IDictionary nestedDictionary)
|
||||
{
|
||||
if (string.Equals(key, InitCustomMapKey, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
InitCustomMap = MergeMaps(InitCustomMap, ToStringMap(nestedDictionary));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.Equals(key, RewardedCustomDataKey, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
RewardedCustomData = MergeMaps(RewardedCustomData, ToStringMap(nestedDictionary));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
map[key] = ConvertDictionaryValue(entry.Value);
|
||||
}
|
||||
|
||||
Channel = GetString(map, ChannelKey, "channel") ?? Channel;
|
||||
@@ -156,6 +180,8 @@ public sealed class ToponControllerOptions
|
||||
ExcludeBundleIds = GetStringArray(map, ExcludeBundleIdsKey) ?? ExcludeBundleIds;
|
||||
RewardedExcludeAdSourceIds = GetStringArray(map, RewardedExcludeAdSourceIdsKey) ?? RewardedExcludeAdSourceIds;
|
||||
QueryAreaOnInit = GetBool(map, QueryAreaOnInitKey) ?? QueryAreaOnInit;
|
||||
InitCustomMap = MergeMaps(InitCustomMap, GetPrefixedMap(map, InitCustomMapKey + "."));
|
||||
RewardedCustomData = MergeMaps(RewardedCustomData, GetPrefixedMap(map, RewardedCustomDataKey + "."));
|
||||
}
|
||||
|
||||
private static string GetString(IDictionary<string, string> map, params string[] keys)
|
||||
@@ -225,6 +251,54 @@ public sealed class ToponControllerOptions
|
||||
return items.Length > 0 ? items : null;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> GetPrefixedMap(IDictionary<string, string> map, string prefix)
|
||||
{
|
||||
var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var pair in map)
|
||||
{
|
||||
if (!pair.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var nestedKey = pair.Key.Substring(prefix.Length).Trim();
|
||||
if (string.IsNullOrWhiteSpace(nestedKey) || string.IsNullOrWhiteSpace(pair.Value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
result[nestedKey] = pair.Value.Trim();
|
||||
}
|
||||
|
||||
return result.Count > 0 ? result : null;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> MergeMaps(
|
||||
Dictionary<string, string> current,
|
||||
Dictionary<string, string> incoming)
|
||||
{
|
||||
if (incoming == null || incoming.Count == 0)
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
var result = current != null
|
||||
? new Dictionary<string, string>(current, StringComparer.OrdinalIgnoreCase)
|
||||
: new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (var pair in incoming)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(pair.Key) || string.IsNullOrWhiteSpace(pair.Value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
result[pair.Key] = pair.Value;
|
||||
}
|
||||
|
||||
return result.Count > 0 ? result : null;
|
||||
}
|
||||
|
||||
private static bool TryConvertBool(object value, out bool result)
|
||||
{
|
||||
switch (value)
|
||||
@@ -287,4 +361,27 @@ public sealed class ToponControllerOptions
|
||||
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> ToStringMap(IDictionary dictionary)
|
||||
{
|
||||
var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (DictionaryEntry entry in dictionary)
|
||||
{
|
||||
if (entry.Key == null || entry.Value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var key = entry.Key.ToString()?.Trim();
|
||||
var value = entry.Value.ToString()?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
result[key] = value;
|
||||
}
|
||||
|
||||
return result.Count > 0 ? result : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user