diff --git a/AnyThinkPlugin/Script/IntegrationManager/Editor/ATConfig.cs b/AnyThinkPlugin/Script/IntegrationManager/Editor/ATConfig.cs index cc693e2..f4b08cb 100644 --- a/AnyThinkPlugin/Script/IntegrationManager/Editor/ATConfig.cs +++ b/AnyThinkPlugin/Script/IntegrationManager/Editor/ATConfig.cs @@ -19,6 +19,18 @@ namespace AnyThink.Scripts.IntegrationManager.Editor public static string PLUGIN_VERSION = "2.1.7"; public static bool isDebug = false; + public static bool EnableEditorTools + { + get + { +#if AnyThinkSDKEditor + return true; +#else + return false; +#endif + } + } + public static int PLUGIN_TYPE = 1; public static int OS_ANDROID = 1; public static int OS_IOS = 2; diff --git a/AnyThinkPlugin/Script/IntegrationManager/Editor/ATIntegrationManager.cs b/AnyThinkPlugin/Script/IntegrationManager/Editor/ATIntegrationManager.cs index adea8f4..4d9f45b 100644 --- a/AnyThinkPlugin/Script/IntegrationManager/Editor/ATIntegrationManager.cs +++ b/AnyThinkPlugin/Script/IntegrationManager/Editor/ATIntegrationManager.cs @@ -42,6 +42,12 @@ namespace AnyThink.Scripts.IntegrationManager.Editor public IEnumerator loadPluginData(Action callback) { + if (!ATConfig.EnableEditorTools) + { + callback?.Invoke(null); + yield break; + } + var anythinkVersionRequest = UnityWebRequest.Get(ATNetInfo.getPluginConfigUrl(ATConfig.PLUGIN_VERSION)); var webRequest = anythinkVersionRequest.SendWebRequest(); while (!webRequest.isDone) @@ -74,6 +80,11 @@ namespace AnyThink.Scripts.IntegrationManager.Editor public IEnumerator loadNetworksData(PluginData pluginData, Action callback) { + if (!ATConfig.EnableEditorTools) + { + callback?.Invoke(pluginData); + yield break; + } Network network = pluginData.anyThink; if (pluginData == null) @@ -125,11 +136,22 @@ namespace AnyThink.Scripts.IntegrationManager.Editor /// public void downloadPlugin(Network network, int os =1, bool showImport = false) { + if (!ATConfig.EnableEditorTools) + { + ATLog.log("downloadPlugin() >>> AnyThinkSDKEditor disabled, skip remote download."); + return; + } + ATEditorCoroutine.startCoroutine(downloadPluginWithEnumerator(network, os, showImport)); } public IEnumerator downloadPluginWithEnumerator(Network network, int os, bool showImport) { + if (!ATConfig.EnableEditorTools) + { + yield break; + } + ATLog.log("downloadPluginWithEnumerator() >>> networkName: " + network.Name + " os: " + os); // if (downloadPluginRequest != null) // { @@ -190,6 +212,12 @@ namespace AnyThink.Scripts.IntegrationManager.Editor //默认下载core包,在下载完network的数据时。 public void downloadCorePlugin(PluginData pluginData) { + if (!ATConfig.EnableEditorTools) + { + ATLog.log("downloadCorePlugin() >>> AnyThinkSDKEditor disabled, skip remote download."); + return; + } + mPluginData = pluginData; var requestParams = pluginData.requestParams; var pluginSettingData = pluginData.pluginSettingData; @@ -278,6 +306,12 @@ namespace AnyThink.Scripts.IntegrationManager.Editor public void networkInstallOrUpdate(PluginData pluginData, Network network, int os) { + if (!ATConfig.EnableEditorTools) + { + ATLog.log("networkInstallOrUpdate() >>> AnyThinkSDKEditor disabled, skip remote download."); + return; + } + downloadPlugin(network, os); } diff --git a/AnyThinkPlugin/Script/IntegrationManager/Editor/ATIntegrationManagerWindow.cs b/AnyThinkPlugin/Script/IntegrationManager/Editor/ATIntegrationManagerWindow.cs index 0edff04..2c69918 100644 --- a/AnyThinkPlugin/Script/IntegrationManager/Editor/ATIntegrationManagerWindow.cs +++ b/AnyThinkPlugin/Script/IntegrationManager/Editor/ATIntegrationManagerWindow.cs @@ -61,6 +61,11 @@ namespace AnyThink.Scripts.IntegrationManager.Editor public static void ShowManager() { + if (!ATConfig.EnableEditorTools) + { + return; + } + var manager = GetWindow(utility: true, title: windowTitle, focus: true); manager.minSize = windowMinSize; // manager.maxSize = windowMinSize; @@ -125,6 +130,11 @@ namespace AnyThink.Scripts.IntegrationManager.Editor warningIcon = new Texture2D(100, 100, TextureFormat.RGBA32, false); warningIcon.LoadImage(warningIconData); + if (!ATConfig.EnableEditorTools) + { + return; + } + loadPluginData(); //热更新 ATIntegrationHotFix.Instance.loadHotFixData(); @@ -158,6 +168,13 @@ namespace AnyThink.Scripts.IntegrationManager.Editor private void OnGUI() { + if (!ATConfig.EnableEditorTools) + { + GUILayout.Space(10); + EditorGUILayout.HelpBox("AnyThinkSDKEditor 未开启,SDK Manager 已禁用。需要维护 SDK 时请先添加 Scripting Define Symbol: AnyThinkSDKEditor。", MessageType.Info); + return; + } + // OnGUI is called on each frame draw, so we don't want to do any unnecessary calculation if we can avoid it. So only calculate it when the width actually changed. if (Math.Abs(previousWindowWidth - position.width) > 1) { @@ -242,6 +259,13 @@ namespace AnyThink.Scripts.IntegrationManager.Editor //获取插件和SDK的版本数据 private void loadPluginData() { + if (!ATConfig.EnableEditorTools) + { + pluginData = null; + pluginDataLoadFailed = false; + return; + } + if (loadDataCoroutine != null) { loadDataCoroutine.Stop(); @@ -275,6 +299,11 @@ namespace AnyThink.Scripts.IntegrationManager.Editor //获取networks private void loadNetworksData(PluginData pluginData) { + if (!ATConfig.EnableEditorTools) + { + return; + } + ATEditorCoroutine.startCoroutine(ATIntegrationManager.Instance.loadNetworksData(pluginData, data => { pluginData = data; @@ -859,4 +888,4 @@ namespace AnyThink.Scripts.IntegrationManager.Editor } } } -} \ No newline at end of file +} diff --git a/AnyThinkPlugin/Script/IntegrationManager/Editor/ATIntergrationHotFix.cs b/AnyThinkPlugin/Script/IntegrationManager/Editor/ATIntergrationHotFix.cs index 6cede7e..6acfca1 100644 --- a/AnyThinkPlugin/Script/IntegrationManager/Editor/ATIntergrationHotFix.cs +++ b/AnyThinkPlugin/Script/IntegrationManager/Editor/ATIntergrationHotFix.cs @@ -26,12 +26,23 @@ namespace AnyThink.Scripts.IntegrationManager.Editor public void loadHotFixData() { + if (!ATConfig.EnableEditorTools) + { + ATLog.log("loadHotFixData() >>> AnyThinkSDKEditor disabled, skip hotfix check."); + return; + } + var downloadUrl = ATNetInfo.getHotfixPluginDownloadUrl(ATConfig.PLUGIN_VERSION); ATLog.log("loadHotFixData() >>> downloadUrl: " + downloadUrl); ATEditorCoroutine.startCoroutine(loadHotFixDataWithIEnumerator(downloadUrl)); } private IEnumerator loadHotFixDataWithIEnumerator(string url) { + if (!ATConfig.EnableEditorTools) + { + yield break; + } + var hotFixDataRequest = UnityWebRequest.Get(url); var webRequest = hotFixDataRequest.SendWebRequest(); while (!webRequest.isDone) @@ -86,6 +97,11 @@ namespace AnyThink.Scripts.IntegrationManager.Editor } private IEnumerator loadHotFixPlugin(HotfixPluginData hotFixDataObj) { + if (!ATConfig.EnableEditorTools) + { + yield break; + } + var path = Path.Combine(Application.temporaryCachePath, hotFixDataObj.file_name); ATLog.log("downloadPluginWithEnumerator() >>> path: " + path); #if UNITY_2017_2_OR_NEWER @@ -161,4 +177,4 @@ namespace AnyThink.Scripts.IntegrationManager.Editor return JsonUtility.FromJson(json); } } -} \ No newline at end of file +} diff --git a/AnyThinkPlugin/Script/IntegrationManager/Editor/ATMenuItems.cs b/AnyThinkPlugin/Script/IntegrationManager/Editor/ATMenuItems.cs index 5781027..55b3d87 100644 --- a/AnyThinkPlugin/Script/IntegrationManager/Editor/ATMenuItems.cs +++ b/AnyThinkPlugin/Script/IntegrationManager/Editor/ATMenuItems.cs @@ -7,6 +7,7 @@ namespace AnyThink.Scripts.IntegrationManager.Editor { public class AnyThinkMenuItems : MonoBehaviour { +#if AnyThinkSDKEditor /** * The special characters at the end represent a shortcut for this action. * @@ -33,5 +34,6 @@ namespace AnyThink.Scripts.IntegrationManager.Editor // } Application.OpenURL("https://newdocs.toponad.com/docs/lgfbO4"); } +#endif } -} \ No newline at end of file +} diff --git a/Topon_Adapter/Runtime/Scripts/ADListenerAggregator.cs b/Topon_Adapter/Runtime/Scripts/ADListenerAggregator.cs index 3b6893c..cbb06dd 100644 --- a/Topon_Adapter/Runtime/Scripts/ADListenerAggregator.cs +++ b/Topon_Adapter/Runtime/Scripts/ADListenerAggregator.cs @@ -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的主线程) diff --git a/Topon_Adapter/Runtime/Scripts/ToponAdController.cs b/Topon_Adapter/Runtime/Scripts/ToponAdController.cs index a7775d8..449dd4d 100644 --- a/Topon_Adapter/Runtime/Scripts/ToponAdController.cs +++ b/Topon_Adapter/Runtime/Scripts/ToponAdController.cs @@ -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); diff --git a/Topon_Adapter/Runtime/Scripts/ToponControllerOptions.cs b/Topon_Adapter/Runtime/Scripts/ToponControllerOptions.cs index 546909e..9ac57b1 100644 --- a/Topon_Adapter/Runtime/Scripts/ToponControllerOptions.cs +++ b/Topon_Adapter/Runtime/Scripts/ToponControllerOptions.cs @@ -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 InitCustomMap { get; set; } + public Dictionary RewardedCustomData { get; set; } public Action OnAreaReceived { get; set; } public Action 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 map, params string[] keys) @@ -225,6 +251,54 @@ public sealed class ToponControllerOptions return items.Length > 0 ? items : null; } + private static Dictionary GetPrefixedMap(IDictionary map, string prefix) + { + var result = new Dictionary(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 MergeMaps( + Dictionary current, + Dictionary incoming) + { + if (incoming == null || incoming.Count == 0) + { + return current; + } + + var result = current != null + ? new Dictionary(current, StringComparer.OrdinalIgnoreCase) + : new Dictionary(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 ToStringMap(IDictionary dictionary) + { + var result = new Dictionary(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; + } } diff --git a/package.json b/package.json index 21f8bad..b416db6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.commercialization.topon", "displayName": "Commercialization.topon", "description": "基于topon的广告sdk封装,依赖基础商业化模块", - "version": "1.4.1", + "version": "1.4.2", "unity": "2021.1", "license": "MIT", "repository": {