123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862 |
- using System;
- using System.Collections;
- using System.IO;
- using System.Linq;
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections.Generic;
- using System.Text;
- namespace AnyThink.Scripts.IntegrationManager.Editor
- {
- public class ATIntegrationManagerWindow : EditorWindow
- {
- private const string windowTitle = "AnyThink Integration Manager";
- private const string uninstallIconExportPath = "AnyThinkPlugin/Resources/Images/uninstall_icon.png";
- private const string alertIconExportPath = "AnyThinkPlugin/Resources/Images/alert_icon.png";
- private const string warningIconExportPath = "AnyThinkPlugin/Resources/Images/warning_icon.png";
- private static readonly Color darkModeTextColor = new Color(0.29f, 0.6f, 0.8f);
- private GUIStyle titleLabelStyle;
- private GUIStyle headerLabelStyle;
- private GUIStyle environmentValueStyle;
- private GUIStyle wrapTextLabelStyle;
- private GUIStyle linkLabelStyle;
- private GUIStyle iconStyle;
- private GUIStyle tipTextStyle;
- private Texture2D uninstallIcon;
- private Texture2D alertIcon;
- private Texture2D warningIcon;
- private Vector2 scrollPosition;
- private static readonly Vector2 windowMinSize = new Vector2(850, 750);
- private const float actionFieldWidth = 80f;
- private const float upgradeAllButtonWidth = 80f;
- private const float networkFieldMinWidth = 200f;
- private const float versionFieldMinWidth = 200f;
- private const float privacySettingLabelWidth = 200f;
- private const float networkFieldWidthPercentage = 0.22f;
- private const float versionFieldWidthPercentage = 0.36f; // There are two version fields. Each take 40% of the width, network field takes the remaining 20%.
- private static float previousWindowWidth = windowMinSize.x;
- private static GUILayoutOption networkWidthOption = GUILayout.Width(networkFieldMinWidth);
- private static GUILayoutOption versionWidthOption = GUILayout.Width(versionFieldMinWidth);
- private static GUILayoutOption sdkKeyTextFieldWidthOption = GUILayout.Width(520);
- private static GUILayoutOption privacySettingFieldWidthOption = GUILayout.Width(400);
- private static readonly GUILayoutOption fieldWidth = GUILayout.Width(actionFieldWidth);
- private static readonly GUILayoutOption upgradeAllButtonFieldWidth = GUILayout.Width(upgradeAllButtonWidth);
- private ATEditorCoroutine loadDataCoroutine;
- private PluginData pluginData;
- private bool pluginDataLoadFailed;
- private bool networkButtonsEnabled = true;
- private bool shouldShowGoogleWarning;
- private int curSelectCountryInt;
- // private int dropdownIndex = 0;
- private int androidVersionPopupIndex;
- private int iosVersionPopupIndex;
- public static void ShowManager()
- {
- var manager = GetWindow<ATIntegrationManagerWindow>(utility: true, title: windowTitle, focus: true);
- manager.minSize = windowMinSize;
- // manager.maxSize = windowMinSize;
- }
- //定义UI的Style
- private void Awake()
- {
- titleLabelStyle = new GUIStyle(EditorStyles.label)
- {
- fontSize = 14,
- fontStyle = FontStyle.Bold,
- fixedHeight = 20
- };
- headerLabelStyle = new GUIStyle(EditorStyles.label)
- {
- fontSize = 12,
- fontStyle = FontStyle.Bold,
- fixedHeight = 18
- };
- environmentValueStyle = new GUIStyle(EditorStyles.label)
- {
- alignment = TextAnchor.MiddleRight
- };
- linkLabelStyle = new GUIStyle(EditorStyles.label)
- {
- wordWrap = true,
- normal = { textColor = EditorGUIUtility.isProSkin ? darkModeTextColor : Color.blue }
- };
- wrapTextLabelStyle = new GUIStyle(EditorStyles.label)
- {
- wordWrap = true
- };
- iconStyle = new GUIStyle(EditorStyles.miniButton)
- {
- fixedWidth = 18,
- fixedHeight = 18,
- padding = new RectOffset(1, 1, 1, 1)
- };
- tipTextStyle = new GUIStyle(EditorStyles.label)
- {
- normal = { textColor = Color.yellow }
- };
- // Load uninstall icon texture.
- var uninstallIconData = File.ReadAllBytes(ATSdkUtil.GetAssetPathForExportPath(uninstallIconExportPath));
- uninstallIcon = new Texture2D(100, 100, TextureFormat.RGBA32, false); // 1. Initial size doesn't matter here, will be automatically resized once the image asset is loaded. 2. Set mipChain to false, else the texture has a weird blurry effect.
- uninstallIcon.LoadImage(uninstallIconData);
- // Load alert icon texture.
- var alertIconData = File.ReadAllBytes(ATSdkUtil.GetAssetPathForExportPath(alertIconExportPath));
- alertIcon = new Texture2D(100, 100, TextureFormat.RGBA32, false);
- alertIcon.LoadImage(alertIconData);
- // Load warning icon texture.
- var warningIconData = File.ReadAllBytes(ATSdkUtil.GetAssetPathForExportPath(warningIconExportPath));
- warningIcon = new Texture2D(100, 100, TextureFormat.RGBA32, false);
- warningIcon.LoadImage(warningIconData);
- loadPluginData();
- //热更新
- ATIntegrationHotFix.Instance.loadHotFixData();
- }
- //这个方法在插件启动时会调用,然后脚本重新加载时也会重新调用,所以加载数据放在Awake中
- private void OnEnable()
- {
- }
- private void OnDisable()
- {
- if (loadDataCoroutine != null)
- {
- loadDataCoroutine.Stop();
- loadDataCoroutine = null;
- }
- ATIntegrationManager.Instance.CancelDownload();
- EditorUtility.ClearProgressBar();
- // Saves the AppLovinSettings object if it has been changed.
- AssetDatabase.SaveAssets();
- }
- private void OnDestroy() {
- ATLog.log("OnDestroy() >>> called");
- }
- private void OnGUI()
- {
- // 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)
- {
- previousWindowWidth = position.width;
- CalculateFieldWidth();
- }
- using (var scrollView = new EditorGUILayout.ScrollViewScope(scrollPosition, false, false))
- {
- scrollPosition = scrollView.scrollPosition;
- GUILayout.Space(5);
- // EditorGUILayout.LabelField("Region (Only for Android, iOS is not affected by region)", titleLabelStyle);
- EditorGUILayout.LabelField("Region", titleLabelStyle);
- DrawCountryUI();
- DrawCountrySwitchTip();
- DrawAndroidXUI();
- DrawAdombAppId();
- EditorGUILayout.LabelField("AnyThink Plugin Details", titleLabelStyle);
- //显示插件版本号
- DrawPluginDetails();
- //绘制SDK版本下架提示
- DrawSdkVersionOffTip();
- //绘制Networks
- DrawMediatedNetworks();
- }
- if (GUI.changed)
- {
- AssetDatabase.SaveAssets();
- }
- }
- /// <summary>
- /// Callback method that will be called with progress updates when the plugin is being downloaded.
- /// </summary>
- public static void OnDownloadPluginProgress(string pluginName, float progress, bool done)
- {
- ATLog.logFormat("OnDownloadPluginProgress() >>> pluginName: {0}, progress: {1}, done: {2}", new object[] { pluginName, progress, done });
- // Download is complete. Clear progress bar.
- if (done || progress == 1)
- {
- EditorUtility.ClearProgressBar();
- AssetDatabase.Refresh();
- }
- // Download is in progress, update progress bar.
- else
- {
- if (EditorUtility.DisplayCancelableProgressBar(windowTitle, string.Format("Downloading {0} plugin...", pluginName), progress))
- {
- ATLog.log("OnDownloadPluginProgress() >>> click cancel download");
- ATIntegrationManager.Instance.CancelDownload();
- EditorUtility.ClearProgressBar();
- AssetDatabase.Refresh();
- }
- }
- }
- public void DeleteSdkVersion(PluginData pluginData, int index, int os) {
- var sdkVersion = "";
- if (os == ATConfig.OS_IOS) {
- sdkVersion = pluginData.iosVersions[index];
- } else {
- sdkVersion = pluginData.androidVersions[index];
- }
- ATIntegrationManager.Instance.deleteSdk(pluginData, sdkVersion, os);
- }
- public void ExChangeSDKVersion(PluginData pluginData, int index, int os) {
- NetworkRequestParams requestParams = pluginData.requestParams;
- if (requestParams == null) {
- requestParams = new NetworkRequestParams();
- }
- requestParams.os = os;
- if (os == ATConfig.OS_ANDROID) { //Android
- requestParams.androidVersion = pluginData.androidVersions[index];
- } else {
- requestParams.iosVersion = pluginData.iosVersions[index];
- }
- pluginData.requestParams = requestParams;
- // ATLog.log("ExChangeSDKVersion() >>> versions.Android: " + versions.Android + " versions.Ios: " + versions.Ios);
- loadNetworksData(pluginData);
- }
- //获取插件和SDK的版本数据
- private void loadPluginData()
- {
- if (loadDataCoroutine != null)
- {
- loadDataCoroutine.Stop();
- }
- loadDataCoroutine = ATEditorCoroutine.startCoroutine(ATIntegrationManager.Instance.loadPluginData(data =>
- {
- if (data == null)
- {
- pluginDataLoadFailed = true;
- }
- else
- {
- ATLog.log("loadNetworksData() >>> pluginData: " + data);
- pluginData = data;
- pluginDataLoadFailed = false;
- var versions = pluginData.anyThink.CurrentVersions;
- if (versions != null) {
- var requestParams = new NetworkRequestParams();
- requestParams.androidVersion = versions.Android;
- requestParams.iosVersion = versions.Ios;
- pluginData.requestParams = requestParams;
- }
- loadNetworksData(pluginData);
- }
- CalculateFieldWidth();
- Repaint();
- }));
- }
- //获取networks
- private void loadNetworksData(PluginData pluginData)
- {
- ATEditorCoroutine.startCoroutine(ATIntegrationManager.Instance.loadNetworksData(pluginData, data =>
- {
- pluginData = data;
- Network network = pluginData.anyThink;
- if (!string.IsNullOrEmpty(network.AndroidDownloadUrl) || !string.IsNullOrEmpty(network.iOSDownloadloadUrl)) {
- ATIntegrationManager.Instance.downloadCorePlugin(data);
- }
- Repaint();
- }));
- }
- //切换国家,重新加载数据
- private void switchCountry(int country)
- {
- ATIntegrationManager.Instance.switchCountry(pluginData, country);
- //重新开始走network
- loadPluginData();
- }
- private void CalculateFieldWidth()
- {
- var currentWidth = position.width;
- var availableWidth = currentWidth - actionFieldWidth - 80; // NOTE: Magic number alert. This is the sum of all the spacing the fields and other UI elements.
- var networkLabelWidth = Math.Max(networkFieldMinWidth, availableWidth * networkFieldWidthPercentage);
- networkWidthOption = GUILayout.Width(networkLabelWidth);
- var versionLabelWidth = Math.Max(versionFieldMinWidth, availableWidth * versionFieldWidthPercentage);
- versionWidthOption = GUILayout.Width(versionLabelWidth);
- const int textFieldOtherUiElementsWidth = 45; // NOTE: Magic number alert. This is the sum of all the spacing the fields and other UI elements.
- var availableTextFieldWidth = currentWidth - networkLabelWidth - textFieldOtherUiElementsWidth;
- sdkKeyTextFieldWidthOption = GUILayout.Width(availableTextFieldWidth);
- var availableUserDescriptionTextFieldWidth = currentWidth - privacySettingLabelWidth - textFieldOtherUiElementsWidth;
- privacySettingFieldWidthOption = GUILayout.Width(availableUserDescriptionTextFieldWidth);
- }
- private void DrawCountryUI()
- {
- // GUILayout.BeginHorizontal();
- GUILayout.Space(4);
- using (new EditorGUILayout.HorizontalScope("box"))
- {
- GUILayout.Space(5);
- int countryInt = ATConfig.getDefCountry(); //默认是中国
- if (pluginData != null)
- {
- countryInt = pluginData.country;
- }
- string[] options = ATConfig.getCountryArray();
- // 创建Dropdown组件
- int curDropdownIndex = ATDataUtil.isChina(countryInt) ? 0 : 1;
- if (options.Length == 1) {
- curDropdownIndex = 0;
- }
- int dropdownIndex = EditorGUILayout.Popup("Select Region:", curDropdownIndex, options);
- if (options.Length > 1) {
- curSelectCountryInt = dropdownIndex == 0 ? ATConfig.CHINA_COUNTRY : ATConfig.NONCHINA_COUNTRY;
- //变化才设置
- if (pluginData != null && curSelectCountryInt != countryInt)
- {
- ATLog.log("DrawCountryUI() >>> curSelectCountryInt: " + curSelectCountryInt + " countryInt: " + countryInt);
- //Unity需要更换Network
- switchCountry(curSelectCountryInt);
- }
- }
- GUILayout.Space(5);
- }
- GUILayout.Space(4);
- // GUILayout.EndHorizontal();
- }
- private void DrawCountrySwitchTip()
- {
- var integratedTip = ATConfig.getRegionIntegrateTip();
- if (string.IsNullOrEmpty(integratedTip)) {
- return;
- }
- GUILayout.Space(4);
- // textStyle.fontStyle = FontStyle.Bold;
- EditorGUILayout.LabelField(integratedTip, tipTextStyle);
- GUILayout.Space(4);
- }
- private void DrawAndroidXUI()
- {
- bool isChina = ATConfig.isSelectedChina();
- // if (!ATConfig.isSelectedChina()) {
- // return;
- // }
- EditorGUILayout.LabelField("AndroidX (Only for Android)", titleLabelStyle);
- GUILayout.Space(4);
- using (new EditorGUILayout.HorizontalScope("box"))
- {
- GUILayout.Space(5);
- int androidXSetting = ATIntegrationManager.Instance.getAndroidXSetting(pluginData);
- string[] options = new string[] { "Default", "Enable", "Disable" };
- if (!isChina) {
- options = new string[] { "Default", "Enable" };
- }
- // 创建Dropdown组件
- int lastDropdownIndex = androidXSetting;
- int curDropdownIndex = EditorGUILayout.Popup("Enable AndroidX:", lastDropdownIndex, options);
- //变化才设置
- if (curDropdownIndex != lastDropdownIndex)
- {
- ATLog.log("DrawAndroidXUI() >>> curDropdownIndex: " + curDropdownIndex + " lastDropdownIndex: " + lastDropdownIndex);
- ATIntegrationManager.Instance.saveAndroidXSetting(pluginData, curDropdownIndex);
- }
- GUILayout.Space(5);
- }
- GUILayout.Space(4);
- }
- private void DrawPluginDetails()
- {
- // GUILayout.BeginHorizontal();
- GUILayout.Space(10);
- using (new EditorGUILayout.VerticalScope("box"))
- {
- // Draw plugin version details
- DrawHeaders("Platform", true);
- DrawPluginDetailRow("Unity Plugin", ATConfig.PLUGIN_VERSION, "", "");
- if (pluginData == null)
- {
- DrawEmptyPluginData("loading sdk data ...");
- return;
- }
- var anythink = pluginData.anyThink;
- var android_version = "";
- var ios_version = "";
- if (anythink != null) {
- android_version = anythink.CurrentVersions.Android;
- ios_version = anythink.CurrentVersions.Ios;
- }
- //绘制Android
- using (new EditorGUILayout.HorizontalScope())
- {
- GUILayout.Space(5);
- EditorGUILayout.LabelField(new GUIContent("Android"), networkWidthOption);
- EditorGUILayout.LabelField(new GUIContent(android_version), versionWidthOption);
- GUILayout.Space(3);
- string[] androidVersions = pluginData.androidVersions;
- if (androidVersions != null && androidVersions.Length > 0) {
- List<int> androidVersionsInt = new List<int>();
- int androidLength = androidVersions.Length;
- for (int i = 0; i < androidLength; i = i + 1)
- {
- androidVersionsInt.Add(i);
- }
- // 创建Dropdown组件
- androidVersionPopupIndex = EditorGUILayout.IntPopup(androidVersionPopupIndex, androidVersions, androidVersionsInt.ToArray(), versionWidthOption);
- GUILayout.FlexibleSpace();
- string selectedAndroidVersion = androidVersions[androidVersionPopupIndex];
- string action = "Exchange";
- if (!string.IsNullOrEmpty(android_version) && Equals(android_version, selectedAndroidVersion)) {
- action = "Delete";
- }
- GUI.enabled = (!Equals(android_version, selectedAndroidVersion)) || action == "Delete";
- if (GUILayout.Button(new GUIContent(action), fieldWidth))
- {
- //切换AndroidSDK版本
- if (action == "Delete") {
- DeleteSdkVersion(pluginData, androidVersionPopupIndex, ATConfig.OS_ANDROID);
- } else {
- ExChangeSDKVersion(pluginData, androidVersionPopupIndex, ATConfig.OS_ANDROID);
- }
- }
- GUI.enabled = true;
- GUILayout.Space(5);
- } else {
- EditorGUILayout.LabelField(new GUIContent("loading..."), versionWidthOption);
- }
-
- GUILayout.Space(3);
- }
- //绘制iOS
- using (new EditorGUILayout.HorizontalScope())
- {
- GUILayout.Space(5);
- EditorGUILayout.LabelField(new GUIContent("iOS"), networkWidthOption);
- EditorGUILayout.LabelField(new GUIContent(ios_version), versionWidthOption);
- GUILayout.Space(3);
- string[] iosVersions = pluginData.iosVersions;
- if (iosVersions != null && iosVersions.Length > 0) {
- List<int> iosVersionsInt = new List<int>();
- int androidLength = iosVersions.Length;
- for (int i = 0; i < androidLength; i = i + 1)
- {
- iosVersionsInt.Add(i);
- }
- // 创建Dropdown组件
- iosVersionPopupIndex = EditorGUILayout.IntPopup(iosVersionPopupIndex, iosVersions, iosVersionsInt.ToArray(), versionWidthOption);
- GUILayout.FlexibleSpace();
- string selectedIosVersion = iosVersions[iosVersionPopupIndex];
- string action = "Exchange";
- if (!string.IsNullOrEmpty(ios_version) && Equals(ios_version, selectedIosVersion)) {
- action = "Delete";
- }
- GUI.enabled = !Equals(ios_version, selectedIosVersion) || action == "Delete";
- if (GUILayout.Button(new GUIContent(action), fieldWidth))
- {
- if (action == "Delete") {
- DeleteSdkVersion(pluginData, iosVersionPopupIndex, ATConfig.OS_IOS);
- } else {
- ExChangeSDKVersion(pluginData, iosVersionPopupIndex, ATConfig.OS_IOS);
- }
- }
- GUI.enabled = true;
- GUILayout.Space(5);
- } else {
- EditorGUILayout.LabelField(new GUIContent("loading..."), versionWidthOption);
- }
-
- GUILayout.Space(3);
- }
- GUILayout.Space(4);
- #if !UNITY_2018_2_OR_NEWER
- EditorGUILayout.HelpBox("AnyThink Unity plugin will soon require Unity 2018.2 or newer to function. Please upgrade to a newer Unity version.", MessageType.Warning);
- #endif
- }
- GUILayout.Space(5);
- // GUILayout.EndHorizontal();
- }
- private void DrawSdkVersionOffTip()
- {
- if (pluginData == null) {
- return;
- }
- var anythink = pluginData.anyThink;
- if (anythink == null) {
- return;
- }
- var android_version = "";
- var ios_version = "";
- if (anythink != null) {
- android_version = anythink.CurrentVersions.Android;
- ios_version = anythink.CurrentVersions.Ios;
- //判断android版本是否版本列表中
- string[] androidVersions = pluginData.androidVersions;
- string[] iosVersions = pluginData.iosVersions;
- //The currently installed Android version and io version have been offline
- StringBuilder sb = new StringBuilder();
- sb.Append("Tips: The currently installed ");
-
- var android_version_off = false;
- if (!string.IsNullOrEmpty(android_version) && androidVersions != null && androidVersions.Length > 0) {
- if (!IsCharInStringArray(android_version, androidVersions)) {
- sb.Append("Android version(");
- sb.Append(android_version);
- sb.Append(") ");
- android_version_off = true;
- }
- }
- var ios_version_off = false;
- if (!string.IsNullOrEmpty(ios_version) && iosVersions != null && iosVersions.Length > 0) {
- if (!IsCharInStringArray(ios_version, iosVersions)) {
- if (android_version_off) {
- sb.Append("and ");
- }
- sb.Append("iOS version(");
- sb.Append(ios_version);
- sb.Append(") ");
- ios_version_off = true;
- }
- }
- if (android_version_off || ios_version_off) {
- sb.Append("have been offline, please install the latest version.");
- GUILayout.Space(4);
- EditorGUILayout.LabelField(sb.ToString(), tipTextStyle);
- GUILayout.Space(4);
- } else {
- sb.Clear();
- }
- }
- }
- private bool IsCharInStringArray(string character, string[] array)
- {
- // 遍历数组中的每个字符串
- foreach (string str in array)
- {
- // 如果当前字符串包含指定的字符,则返回true
- if (str == character)
- {
- return true;
- }
- }
- // 如果没有找到字符,则返回false
- return false;
- }
- private void DrawHeaders(string firstColumnTitle, bool drawAction)
- {
- using (new EditorGUILayout.HorizontalScope())
- {
- GUILayout.Space(5);
- EditorGUILayout.LabelField(firstColumnTitle, headerLabelStyle, networkWidthOption);
- EditorGUILayout.LabelField("Current Version", headerLabelStyle, versionWidthOption);
- GUILayout.Space(3);
- EditorGUILayout.LabelField("SDK Versions", headerLabelStyle, versionWidthOption);
- GUILayout.Space(3);
- if (drawAction)
- {
- GUILayout.FlexibleSpace();
- GUILayout.Button("Actions", headerLabelStyle, fieldWidth);
- GUILayout.Space(5);
- }
- }
- GUILayout.Space(4);
- }
- private void DrawPluginDetailRow(string platform, string currentVersion, string sdkversions, string actions)
- {
- using (new EditorGUILayout.HorizontalScope())
- {
- GUILayout.Space(5);
- EditorGUILayout.LabelField(new GUIContent(platform), networkWidthOption);
- EditorGUILayout.LabelField(new GUIContent(currentVersion), versionWidthOption);
- GUILayout.Space(3);
- EditorGUILayout.LabelField(new GUIContent(sdkversions), versionWidthOption);
- GUILayout.Space(3);
- // EditorGUILayout.LabelField(new GUIContent(actions), versionWidthOption);
- // GUILayout.Space(3);
- }
- GUILayout.Space(4);
- }
- private void DrawEmptyPluginData(string tip)
- {
- GUILayout.Space(5);
- // Plugin data failed to load. Show error and retry button.
- if (pluginDataLoadFailed)
- {
- GUILayout.Space(10);
- GUILayout.BeginHorizontal();
- GUILayout.Space(5);
- EditorGUILayout.LabelField("Failed to load plugin data. Please click retry or restart the integration manager.", titleLabelStyle);
- if (GUILayout.Button("Retry", fieldWidth))
- {
- pluginDataLoadFailed = false;
- loadPluginData();
- }
- GUILayout.Space(5);
- GUILayout.EndHorizontal();
- GUILayout.Space(10);
- }
- // Still loading, show loading label.
- else
- {
- GUILayout.Space(10);
- GUILayout.BeginHorizontal();
- // GUILayout.FlexibleSpace();
- EditorGUILayout.LabelField(tip, titleLabelStyle);
- // GUILayout.FlexibleSpace();
- GUILayout.EndHorizontal();
- GUILayout.Space(10);
- }
- GUILayout.Space(5);
- }
- //绘制Admob Id
- private void DrawAdombAppId() {
- var integrationManager = ATIntegrationManager.Instance;
- bool isAdmobInstalledForAndroid = integrationManager.isAdmobInstalled(ATConfig.OS_ANDROID);
- bool isAdmobInstalledForIos = integrationManager.isAdmobInstalled(ATConfig.OS_IOS);
- if (isAdmobInstalledForAndroid || isAdmobInstalledForIos) {
- EditorGUILayout.LabelField("Admob AppId", titleLabelStyle);
- GUILayout.Space(5);
- using (new EditorGUILayout.VerticalScope("box"))
- {
- GUILayout.Space(10);
- if (isAdmobInstalledForAndroid) {
- var androidAdmobAppId = DrawTextField("App ID (Android)", integrationManager.getAdmobAppIdByOs(pluginData, ATConfig.OS_ANDROID), networkWidthOption);
- integrationManager.setAdmobAppidByOs(pluginData, ATConfig.OS_ANDROID, androidAdmobAppId);
- }
- if (isAdmobInstalledForIos) {
- if (isAdmobInstalledForAndroid) {
- GUILayout.Space(10);
- }
- var iosAdmobAppId = DrawTextField("App ID (iOS)", integrationManager.getAdmobAppIdByOs(pluginData, ATConfig.OS_IOS), networkWidthOption);
- integrationManager.setAdmobAppidByOs(pluginData, ATConfig.OS_IOS, iosAdmobAppId);
- }
- }
- }
- }
- private string DrawTextField(string fieldTitle, string text, GUILayoutOption labelWidth, GUILayoutOption textFieldWidthOption = null)
- {
- GUILayout.BeginHorizontal();
- GUILayout.Space(4);
- EditorGUILayout.LabelField(new GUIContent(fieldTitle), labelWidth);
- GUILayout.Space(4);
- text = (textFieldWidthOption == null) ? GUILayout.TextField(text) : GUILayout.TextField(text, textFieldWidthOption);
- GUILayout.Space(4);
- GUILayout.EndHorizontal();
- GUILayout.Space(4);
- return text;
- }
- private void DrawMediatedNetworks()
- {
- GUILayout.Space(5);
- EditorGUILayout.LabelField("Ad Networks", titleLabelStyle);
- GUILayout.Space(5);
- GUILayout.BeginHorizontal();
- using (new EditorGUILayout.VerticalScope("box"))
- {
- DrawHeaders("Network", true);
- string clickTip = "You need to select an sdk version and click the Exchange button.";
- // Immediately after downloading and importing a plugin the entire IDE reloads and current versions can be null in that case. Will just show loading text in that case.
- if (pluginData == null)
- {
- ATLog.log("DrawMediatedNetworks failed.");
- DrawEmptyPluginData("loading sdk data ...");
- } else if(pluginData.mediatedNetworks == null) {
- DrawEmptyPluginData(clickTip);
- } else {
- var networks = pluginData.mediatedNetworks;
- var length = networks.Length;
- ATLog.log("DrawMediatedNetworks() >>> networks length: " + length);
- if (length == 0) {
- DrawEmptyPluginData(clickTip);
- return;
- }
- int versionEmptyLength = 0;
- foreach (var network in networks)
- {
- if (network.isVersionEmpty()) {
- // ATLog.log("DrawMediatedNetworks() >>> isVersionEmpty name: " + network.Name);
- versionEmptyLength = versionEmptyLength + 1;
- } else {
- DrawNetworkDetailRow2(network);
- }
- }
- ATLog.log("DrawMediatedNetworks() >>> versionEmptyLength: " + versionEmptyLength);
- if (versionEmptyLength == length) {
- DrawEmptyPluginData(clickTip);
- }
- GUILayout.Space(10);
- }
- }
- GUILayout.Space(5);
- GUILayout.EndHorizontal();
- }
- //绘制network的每一行
- private void DrawNetworkDetailRow2(Network network) {
- using (new EditorGUILayout.VerticalScope("box"))
- {
- GUILayout.Space(4);
- string a_action = "";
- string i_action = "";
- string cur_a_version = "";
- string cur_i_version = "";
- string last_a_version = "";
- string last_i_version = "";
- if (network.CurrentVersions != null)
- {
- cur_a_version = network.CurrentVersions.Android;
- cur_i_version = network.CurrentVersions.Ios;
- }
- if (network.LatestVersions != null)
- {
- last_a_version = network.LatestVersions.Android;
- last_i_version = network.LatestVersions.Ios;
- }
- //Android Action按钮状态
- ATLog.log("DrawNetworkDetailRow2() >>> cur_a_version: " + cur_a_version + " last_i_version: " + last_i_version +
- " name: " + network.DisplayName + " last_a_version: " + last_a_version);
- if (string.IsNullOrEmpty(cur_a_version)) {
- a_action = "Install";
- } else if (ATDataUtil.CompareVersions(cur_a_version, last_a_version) == VersionComparisonResult.Lesser) {
- a_action = "Upgrade";
- } else if(ATDataUtil.CompareVersions(cur_a_version, last_a_version) == VersionComparisonResult.Equal) {
- a_action = "Installed";
- }
- bool hasAndroid = false;
- if (!string.IsNullOrEmpty(last_a_version)) {
- hasAndroid = true;
- DrawRowNetwork(network, ATConfig.OS_ANDROID, cur_a_version, last_a_version, a_action, true);
- }
- //iOS Action按钮状态
- // var i_compare_result = ATDataUtil.CompareVersions(cur_i_version, last_i_version);
- if (string.IsNullOrEmpty(cur_i_version)) {
- i_action = "Install";
- } else if (ATDataUtil.CompareVersions(cur_i_version, last_i_version) == VersionComparisonResult.Lesser) {
- i_action = "Upgrade";
- } else if(ATDataUtil.CompareVersions(cur_i_version, last_i_version) == VersionComparisonResult.Equal) {
- i_action = "Installed";
- }
- if (!string.IsNullOrEmpty(last_i_version)) {
- DrawRowNetwork(network, ATConfig.OS_IOS, cur_i_version, last_i_version, i_action, !hasAndroid);
- }
- GUILayout.Space(4);
- }
- }
- private void DrawRowNetwork(Network network, int os, string curVersion, string lastVersion, string action, bool isShowNetworkName)
- {
- GUILayout.Space(5);
- if (os == ATConfig.OS_ANDROID) {
- if (!string.IsNullOrEmpty(curVersion)) {
- curVersion = "Android-" + curVersion;
- } else {
- curVersion = "Not Installed";
- }
- lastVersion = "Android-" + lastVersion;
- } else {
- if (!string.IsNullOrEmpty(curVersion)) {
- curVersion = "iOS-" + curVersion;
- } else {
- curVersion = "Not Installed";
- }
- lastVersion = "iOS-" + lastVersion;
- }
- using (new EditorGUILayout.HorizontalScope(GUILayout.ExpandHeight(false)))
- {
- GUILayout.Space(5);
- if (isShowNetworkName) {
- EditorGUILayout.LabelField(new GUIContent(network.DisplayName), networkWidthOption);
- } else {
- EditorGUILayout.LabelField(new GUIContent(""), networkWidthOption);
- }
-
- EditorGUILayout.LabelField(new GUIContent(curVersion), versionWidthOption);
- GUILayout.Space(3);
- EditorGUILayout.LabelField(new GUIContent(lastVersion), versionWidthOption);
- GUILayout.Space(3);
- GUILayout.FlexibleSpace();
- if (network.isReqiureUpdate())
- {
- GUILayout.Label(new GUIContent { image = alertIcon, tooltip = "Adapter not compatible, please update to the latest version." }, iconStyle);
- }
- GUI.enabled = action != "Installed";
- if (GUILayout.Button(new GUIContent(action), fieldWidth))
- {
- ATIntegrationManager.Instance.networkInstallOrUpdate(pluginData, network, os);
- }
- GUI.enabled = true;
- GUILayout.Space(2);
- GUI.enabled = action == "Installed";
- if (GUILayout.Button(new GUIContent { image = uninstallIcon, tooltip = "Uninstall" }, iconStyle))
- {
- EditorUtility.DisplayProgressBar("Integration Manager", "Deleting " + network.Name + "...", 0.5f);
- ATIntegrationManager.Instance.uninstallNetwork(network, os);
- //Refresh UI
- AssetDatabase.Refresh();
- EditorUtility.ClearProgressBar();
- }
- GUI.enabled = true;
- GUILayout.Space(5);
- }
- }
- }
- }
|