887 lines
		
	
	
		
			34 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			887 lines
		
	
	
		
			34 KiB
		
	
	
	
		
			C#
		
	
	
| 
 | |
| 
 | |
| using System.Collections.Generic;
 | |
| using System.IO;
 | |
| using Facebook.Unity.Settings;
 | |
| using UnityEditor.Compilation;
 | |
| 
 | |
| namespace Guru.Editor
 | |
| {
 | |
|     using System;
 | |
|     using UnityEditor;
 | |
|     using UnityEngine;
 | |
|     using Guru;
 | |
|     using AppLovinMax.Scripts.IntegrationManager.Editor;
 | |
|     
 | |
|     
 | |
|     public class GuruSDKManager: EditorWindow
 | |
|     {
 | |
|         private const string GURU_SETTINGS_PATH = "Assets/Guru/Resources/GuruSettings.asset";
 | |
|         private const string APPLOVIN_SETTINGS_PATH = "Assets/Guru/Resources/AppLovinSettings.asset";
 | |
|         private const string FACEBOOK_SETTINGS_PATH = "Assets/FacebookSDK/SDK/Resources/FacebookSettings.asset";
 | |
|         private const string ANDROID_KEYSTORE_PATH = "Packages/com.guru.unity.sdk.core/Keystore/guru.jks";
 | |
|         private const string KeyMaxAutoUpdateEnabled = "com.applovin.auto_update_enabled";
 | |
|         
 | |
|         
 | |
|         private static GuruSDKManager _instance;
 | |
|         public static GuruSDKManager Instance {
 | |
|             get
 | |
|             {
 | |
|                 if (_instance == null)
 | |
|                 {
 | |
|                     _instance = GetWindow<GuruSDKManager>();
 | |
|                 }
 | |
|                 return _instance;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private GuruServiceConfig _serviceConfig;
 | |
|         private static GUIStyle _itemTitleStyle;
 | |
|         private static GUIStyle StyleItemTitle
 | |
|         {
 | |
|             get
 | |
|             {
 | |
|                 if (_itemTitleStyle == null)
 | |
|                 {
 | |
|                     _itemTitleStyle = new GUIStyle("BOX")
 | |
|                     {
 | |
|                         fontSize = 12,
 | |
|                         fontStyle = FontStyle.Bold,
 | |
|                         stretchWidth = true,
 | |
|                         alignment = TextAnchor.MiddleLeft,
 | |
|                         padding = new RectOffset(4, 4, 4, 4),
 | |
|                     };
 | |
|                 }
 | |
|                 return _itemTitleStyle;
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private bool _hasCheckingCompleted = false;
 | |
| 
 | |
| 
 | |
|         public GuruSDKManager()
 | |
|         {
 | |
|             this.minSize = new Vector2(480, 640);
 | |
|         }
 | |
|         
 | |
| 
 | |
|         public static void Open()
 | |
|         {
 | |
|             Instance.Show();
 | |
|         }
 | |
| 
 | |
| 
 | |
|         private void OnEnable()
 | |
|         {
 | |
|             titleContent = new GUIContent("Guru SDK Manager");
 | |
|             _serviceConfig = EditorGuruServiceIO.LoadConfig();
 | |
|             if (_serviceConfig != null)
 | |
|             {
 | |
|                 Debug.Log($"<color=#88ff00>[Guru] Load <guru-services> success.</color>");
 | |
|                 CheckServicesCompletion();
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 Debug.Log($"<color=red>[Guru] <guru-services> file not found...</color>");
 | |
|             }
 | |
|         }
 | |
| 
 | |
| 
 | |
|         #region Service Checker
 | |
| 
 | |
|         private const string MARK_FAIL = "#FAIL";
 | |
|         private const string MARK_INDENT = "    ";
 | |
|         private List<string> _completionCheckResult;
 | |
|         private int _serviceCriticalFail = 0;
 | |
|         private int _serviceNormalFail = 0;
 | |
|         
 | |
|         /// <summary>
 | |
|         /// 检查服务文件的配置完整性
 | |
|         /// </summary>
 | |
|         private void CheckServicesCompletion()
 | |
|         {
 | |
|             _serviceCriticalFail = 0;
 | |
|             _serviceNormalFail = 0;
 | |
|             
 | |
|             _completionCheckResult = new List<string>(40);
 | |
|             string mk_yes = " ( \u2714 ) ";
 | |
|             string mk_no = " ( \u2718 ) ";
 | |
|             string mk_star = " ( \u2605 ) ";
 | |
|             string check_passed = $"{MARK_INDENT}{mk_yes} All items passed!";
 | |
|             if (_serviceConfig == null)
 | |
|             {
 | |
|                 AddResultLine($"{mk_yes} guru-services is missing", false);
 | |
|                 AddResultLine($"Please contact Guru tech support to get help.", false);
 | |
|                 _serviceCriticalFail++;
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 bool passed = true;
 | |
|                 AddResultLine($"{mk_star} <guru-services> exists!");
 | |
|                 AddResultLine($"--------------------------------");
 | |
|                 
 | |
|                 //-------- APP Settings --------
 | |
|                 passed = true;
 | |
|                 AddResultLine($"[ App ]");
 | |
|                 if (_serviceConfig.app_settings == null)
 | |
|                 {
 | |
|                     passed = false;
 | |
|                     AddResultLine($"{MARK_INDENT}{mk_no} settings is missing!", false);
 | |
|                     _serviceCriticalFail++;
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     if (_serviceConfig.app_settings.app_id.IsNullOrEmpty())
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} AppID is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                     if (_serviceConfig.app_settings.bundle_id.IsNullOrEmpty())
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} BundleID is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                     if (_serviceConfig.app_settings.product_name.IsNullOrEmpty())
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Product Name is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                     if (_serviceConfig.app_settings.support_email.IsNullOrEmpty())
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Support Email is missing!", false);
 | |
|                         _serviceNormalFail++;
 | |
|                     }
 | |
|                 }
 | |
|                 
 | |
|                 if (passed) AddResultLine(check_passed);
 | |
|                 
 | |
|                 //-------- ADS Settings --------
 | |
|                 passed = true;
 | |
|                 AddResultLine($"[ Ads ]");
 | |
|                 if (_serviceConfig.ad_settings == null)
 | |
|                 {
 | |
|                     passed = false;
 | |
|                     AddResultLine($"{MARK_INDENT}{mk_no} settings is missing!", false);
 | |
|                     _serviceCriticalFail++;
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     if (_serviceConfig.ad_settings.sdk_key.IsNullOrEmpty())
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} SDK Key is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                     if (!IsArrayNotEmpty(_serviceConfig.ad_settings.admob_app_id))
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Admob ID is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                     if (!IsArrayNotEmpty(_serviceConfig.ad_settings.max_ids_android))
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} AppLovin Android IDs is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                     if (!IsArrayNotEmpty(_serviceConfig.ad_settings.max_ids_ios))
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} AppLovin iOS IDs is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                     if (!IsArrayNotEmpty(_serviceConfig.ad_settings.amazon_ids_android))
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Amazon Android IDs is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                     if (!IsArrayNotEmpty(_serviceConfig.ad_settings.amazon_ids_ios))
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Amazon iOS IDs is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                     if (!IsArrayNotEmpty(_serviceConfig.ad_settings.pubmatic_ids_android))
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Pubmatic Android IDs is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                     if (!IsArrayNotEmpty(_serviceConfig.ad_settings.pubmatic_ids_ios))
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Pubmatic iOS IDs is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                     if (!IsArrayNotEmpty(_serviceConfig.ad_settings.moloco_ids_android))
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Moloco Android Test IDs is missing!", false);
 | |
|                         _serviceNormalFail++;
 | |
|                     }
 | |
|                     if (!IsArrayNotEmpty(_serviceConfig.ad_settings.moloco_ids_ios))
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Moloco iOS Test IDs is missing!", false);
 | |
|                         _serviceNormalFail++;
 | |
|                     }
 | |
|                 }
 | |
|                 if (passed) AddResultLine(check_passed);
 | |
|                 
 | |
|                 //-------- Channels Settings --------
 | |
|                 passed = true;
 | |
|                 AddResultLine($"[ Channels ]");
 | |
|                 if (_serviceConfig.fb_settings == null)
 | |
|                 {
 | |
|                     passed = false;
 | |
|                     AddResultLine($"{MARK_INDENT}{mk_no} Facebook settings is missing!", false);
 | |
|                     _serviceCriticalFail++;
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     if (_serviceConfig.fb_settings.app_id.IsNullOrEmpty())
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Facebook AppID is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                     if (_serviceConfig.fb_settings.client_token.IsNullOrEmpty())
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Facebook Client Token is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                 }
 | |
| 
 | |
|                 if (_serviceConfig.adjust_settings == null)
 | |
|                 {
 | |
|                     passed = false;
 | |
|                     AddResultLine($"{MARK_INDENT}{mk_no} Adjust settings is missing!", false);
 | |
|                     _serviceCriticalFail++;
 | |
|                 }
 | |
|                 else
 | |
|                 {
 | |
|                     if(!IsArrayNotEmpty(_serviceConfig.adjust_settings.app_token))
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Adjust AppToken is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
| 
 | |
|                     if (!IsArrayNotEmpty(_serviceConfig.adjust_settings.events))
 | |
|                     {
 | |
|                         passed = false;
 | |
|                         AddResultLine($"{MARK_INDENT}{mk_no} Adjust Events is missing!", false);
 | |
|                         _serviceCriticalFail++;
 | |
|                     }
 | |
|                 }
 | |
|                 if (passed) AddResultLine(check_passed);
 | |
|                 
 | |
|                 //-------- IAP --------
 | |
|                 passed = true;
 | |
|                 AddResultLine($"[ IAP ]");
 | |
|                 if (!IsArrayNotEmpty(_serviceConfig.products))
 | |
|                 {
 | |
|                     passed = false;
 | |
|                     AddResultLine($"{MARK_INDENT}{mk_no} Product list is missing!", false);
 | |
|                     _serviceNormalFail++;
 | |
|                 }
 | |
|                 if (passed) AddResultLine(check_passed);
 | |
|             }
 | |
| 
 | |
|         }
 | |
| 
 | |
|         private void AddResultLine(string msg, bool passed = true)
 | |
|         {
 | |
|             if (_completionCheckResult == null)
 | |
|             {
 | |
|                 _completionCheckResult = new List<string>(40);
 | |
|             }
 | |
|             string mk = passed? "" : MARK_FAIL;
 | |
|             _completionCheckResult.Add($"{msg}{mk}");
 | |
|         }
 | |
| 
 | |
|         private void GUI_ServiceCheckResult()
 | |
|         {
 | |
|             if (_completionCheckResult != null)
 | |
|             {
 | |
|                 Color green = new Color(0.7f, 1, 0);
 | |
|                 Color red = new Color(1, 0.2f, 0);
 | |
|                 Color c;
 | |
|                 string line = "";
 | |
|                 for (int i = 0; i < _completionCheckResult.Count; i++)
 | |
|                 {
 | |
|                     c = green;
 | |
|                     line = _completionCheckResult[i];
 | |
|                     if (line.EndsWith(MARK_FAIL))
 | |
|                     {
 | |
|                         line = line.Replace(MARK_FAIL, "");
 | |
|                         c = red;
 | |
|                     }
 | |
|                     GUI_Color(c, () =>
 | |
|                     {
 | |
|                         EditorGUILayout.LabelField(line);
 | |
|                         GUILayout.Space(2);
 | |
|                     });
 | |
|                     
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|         }
 | |
| 
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
| 
 | |
|         
 | |
|         #region GUI
 | |
| 
 | |
|         void OnGUI()
 | |
|         {
 | |
|             // TITLE
 | |
|             GUI_WindowTitle();
 | |
|             
 | |
|             // CONTENT
 | |
|             if (_serviceConfig == null)
 | |
|             {
 | |
|                 GUI_OnConfigDisabled();
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 GUI_OnConfigEnabled();
 | |
|             }
 | |
| 
 | |
|         }
 | |
| 
 | |
|         private void GUI_WindowTitle()
 | |
|         {
 | |
|             GUILayout.Space(4);
 | |
|             
 | |
|             var s = new GUIStyle("BOX")
 | |
|             {
 | |
|                 fontSize = 36,
 | |
|                 fontStyle = FontStyle.Bold,
 | |
|                 alignment = TextAnchor.MiddleCenter,
 | |
|                 stretchWidth = true,
 | |
|                 stretchHeight = true,
 | |
|                 fixedHeight = 60,
 | |
|             };
 | |
| 
 | |
| 
 | |
|             EditorGUILayout.LabelField("Guru SDK",s);
 | |
|             s.fontSize = 13;
 | |
|             s.fixedHeight = 20;
 | |
|             EditorGUILayout.LabelField($"Version {GuruSDK.Version}", s);
 | |
|             
 | |
|             GUILayout.Space(4);
 | |
|         }
 | |
| 
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 配置不可用
 | |
|         /// </summary>
 | |
|         private void GUI_OnConfigDisabled()
 | |
|         {
 | |
|             GUI_Color(new Color(1,0.2f, 0), () =>
 | |
|             {
 | |
|                 EditorGUILayout.LabelField("<>", StyleItemTitle);
 | |
|             });
 | |
|         }
 | |
| 
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 配置可用
 | |
|         /// </summary>
 | |
|         private void GUI_OnConfigEnabled()
 | |
|         {
 | |
|             var box = new GUIStyle("BOX");
 | |
|             float btnH = 40;
 | |
|             
 | |
|             //------------ check allsettings -------------
 | |
|             EditorGUILayout.LabelField("[ Guru Service ]", StyleItemTitle);
 | |
|             GUILayout.Space(2);
 | |
|             GUI_ServiceCheckResult();
 | |
|             GUILayout.Space(16);
 | |
| 
 | |
|             if (_serviceCriticalFail > 0)
 | |
|             {
 | |
|                 // 严重错误过多
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 GUI_Button("IMPORT ALL SETTINGS", () =>
 | |
|                 {
 | |
|                     CheckAllComponents();
 | |
|                 }, null, GUILayout.Height(btnH));
 | |
|             }
 | |
|             
 | |
|             GUILayout.Space(4);
 | |
|          
 | |
|         }
 | |
| 
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
| 
 | |
|         #region Check Components
 | |
| 
 | |
|         private string logBuffer;
 | |
|         
 | |
|         
 | |
|         private void CheckAllComponents()
 | |
|         {
 | |
|             string barTitle = "Setup All Components";
 | |
|             EditorUtility.DisplayCancelableProgressBar(barTitle, "Start collect all components", 0);
 | |
|             Debug.Log("--- Setup All Components ---");
 | |
|             ImportGuruSettings();
 | |
|             EditorUtility.DisplayCancelableProgressBar(barTitle, "GuruSettings is done", 0.2f);
 | |
|             ImportAppLovinSettings();
 | |
|             EditorUtility.DisplayCancelableProgressBar(barTitle, "AppLovinSettings is done", 0.4f);
 | |
|             ImportFacebookSettings();
 | |
|             EditorUtility.DisplayCancelableProgressBar(barTitle, "FacebookSettings is done", 0.6f);
 | |
|             ApplyMods();
 | |
|             EditorUtility.DisplayCancelableProgressBar(barTitle, "All Mods is done", 0.8f);  
 | |
|             
 | |
|             AssetDatabase.SaveAssets();
 | |
|             
 | |
|             CompilationPipeline.RequestScriptCompilation();
 | |
|             CompilationPipeline.compilationFinished += o =>
 | |
|             {
 | |
|                 EditorUtility.ClearProgressBar();
 | |
|                 AssetDatabase.Refresh();
 | |
| 
 | |
|                 EditorUtility.DisplayDialog("Importing Guru Services", "All the settings importing success!", "OK");
 | |
|             };
 | |
|         }
 | |
| 
 | |
|         //------------------------- GuruSettings --------------------------------
 | |
|         private void ImportGuruSettings()
 | |
|         {
 | |
|             GuruSettings settings = null;
 | |
|             if (IsAssetExists(nameof(GuruSettings), GURU_SETTINGS_PATH))
 | |
|             {
 | |
|                 settings = AssetDatabase.LoadAssetAtPath<GuruSettings>(GURU_SETTINGS_PATH);
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 settings = CreateInstance<GuruSettings>();
 | |
|                 AssetDatabase.CreateAsset(settings, GURU_SETTINGS_PATH);
 | |
|             }
 | |
|             settings.CompanyName = "Guru";
 | |
|             settings.ProductName = _serviceConfig.app_settings.product_name;
 | |
|             settings.GameIdentifier = _serviceConfig.app_settings.bundle_id;
 | |
|             settings.PriacyUrl = _serviceConfig.app_settings.privacy_url;
 | |
|             settings.TermsUrl = _serviceConfig.app_settings.terms_url;
 | |
|             settings.SupportEmail = _serviceConfig.app_settings.support_email;
 | |
|             settings.AndroidStoreUrl = _serviceConfig.app_settings.android_store;
 | |
|             settings.IOSStoreUrl = _serviceConfig.app_settings.ios_store;
 | |
|             
 | |
|             SerializedObject so = new SerializedObject(settings);
 | |
|             SerializedProperty n;
 | |
|             SerializedObject nn;
 | |
|             SerializedProperty p;
 | |
|             string[] arr;
 | |
|             
 | |
|             n = so.FindProperty("IPMSetting");
 | |
|             if (null != n)
 | |
|             {
 | |
|                 p = n.serializedObject.FindProperty("IPMSetting.appID");
 | |
|                 p.stringValue = _serviceConfig.app_settings.app_id;
 | |
|                 
 | |
|                 p = n.serializedObject.FindProperty("IPMSetting.tokenValidTime");
 | |
|                 p.intValue = _serviceConfig.app_settings.token_vaild_time;
 | |
|             }
 | |
| 
 | |
|             //---------- AMAZON -----------------------
 | |
|             n = so.FindProperty("AmazonSetting");
 | |
|             if (null != n)
 | |
|             {
 | |
|                 p = n.serializedObject.FindProperty("AmazonSetting.Enable");
 | |
|                 p.boolValue = true;
 | |
|                 
 | |
|                 arr = _serviceConfig.ad_settings.amazon_ids_android;
 | |
|                 if (IsArrayHasLength(arr, 4))
 | |
|                 {
 | |
|                     p = n.serializedObject.FindProperty("AmazonSetting.Android.appID");
 | |
|                     p.stringValue = arr[0];
 | |
|                     p = n.serializedObject.FindProperty("AmazonSetting.Android.bannerSlotID");
 | |
|                     p.stringValue = arr[1];
 | |
|                     p = n.serializedObject.FindProperty("AmazonSetting.Android.interSlotID");
 | |
|                     p.stringValue = arr[2];
 | |
|                     p = n.serializedObject.FindProperty("AmazonSetting.Android.rewardSlotID");
 | |
|                     p.stringValue = arr[3];
 | |
|                 }
 | |
| 
 | |
|                 arr = _serviceConfig.ad_settings.amazon_ids_ios;
 | |
|                 if (IsArrayHasLength(arr, 4))
 | |
|                 {
 | |
|                     p = n.serializedObject.FindProperty("AmazonSetting.iOS.appID");
 | |
|                     p.stringValue = arr[0];
 | |
|                     p = n.serializedObject.FindProperty("AmazonSetting.iOS.bannerSlotID");
 | |
|                     p.stringValue = arr[1];
 | |
|                     p = n.serializedObject.FindProperty("AmazonSetting.iOS.interSlotID");
 | |
|                     p.stringValue = arr[2];
 | |
|                     p = n.serializedObject.FindProperty("AmazonSetting.iOS.rewardSlotID");
 | |
|                     p.stringValue = arr[3];
 | |
|                 }
 | |
|             }
 | |
|             
 | |
|             //---------- PUBMATIC -----------------------
 | |
|             n = so.FindProperty("PubmaticSetting");
 | |
|             if (null != n)
 | |
|             {
 | |
|                 p = n.serializedObject.FindProperty("PubmaticSetting.Enable");
 | |
|                 p.boolValue = true;
 | |
|                 
 | |
|                 arr = _serviceConfig.ad_settings.pubmatic_ids_android;
 | |
|                 if (IsArrayHasLength(arr, 4))
 | |
|                 {
 | |
|                     p = n.serializedObject.FindProperty("PubmaticSetting.Android.storeUrl");
 | |
|                     p.stringValue = arr[0];
 | |
|                     p = n.serializedObject.FindProperty("PubmaticSetting.Android.bannerUnitID");
 | |
|                     p.stringValue = arr[1];
 | |
|                     p = n.serializedObject.FindProperty("PubmaticSetting.Android.interUnitID");
 | |
|                     p.stringValue = arr[2];
 | |
|                     p = n.serializedObject.FindProperty("PubmaticSetting.Android.rewardUnitID");
 | |
|                     p.stringValue = arr[3];
 | |
|                 }
 | |
| 
 | |
|                 arr = _serviceConfig.ad_settings.pubmatic_ids_ios;
 | |
|                 if (IsArrayHasLength(arr, 4))
 | |
|                 {
 | |
|                     p = n.serializedObject.FindProperty("PubmaticSetting.iOS.storeUrl");
 | |
|                     p.stringValue = arr[0];
 | |
|                     p = n.serializedObject.FindProperty("PubmaticSetting.iOS.bannerUnitID");
 | |
|                     p.stringValue = arr[1];
 | |
|                     p = n.serializedObject.FindProperty("PubmaticSetting.iOS.interUnitID");
 | |
|                     p.stringValue = arr[2];
 | |
|                     p = n.serializedObject.FindProperty("PubmaticSetting.iOS.rewardUnitID");
 | |
|                     p.stringValue = arr[3];
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             //---------- MOLOCO -----------------------
 | |
|             n = so.FindProperty("MolocoSetting");
 | |
|             if (null != n)
 | |
|             {
 | |
|                 p = n.serializedObject.FindProperty("MolocoSetting.Enable");
 | |
|                 p.boolValue = true;
 | |
|                 
 | |
|                 arr = _serviceConfig.ad_settings.moloco_ids_android;
 | |
|                 if (IsArrayHasLength(arr, 3))
 | |
|                 {
 | |
|                     p = n.serializedObject.FindProperty("MolocoSetting.Android.bannerTestUnitID");
 | |
|                     p.stringValue = arr[0];
 | |
|                     p = n.serializedObject.FindProperty("MolocoSetting.Android.interTestUnitID");
 | |
|                     p.stringValue = arr[1];
 | |
|                     p = n.serializedObject.FindProperty("MolocoSetting.Android.rewardTestUnitID");
 | |
|                     p.stringValue = arr[2];
 | |
|                 }
 | |
| 
 | |
|                 arr = _serviceConfig.ad_settings.moloco_ids_ios;
 | |
|                 if (IsArrayHasLength(arr, 3))
 | |
|                 {
 | |
|                     p = n.serializedObject.FindProperty("MolocoSetting.iOS.bannerTestUnitID");
 | |
|                     p.stringValue = arr[0];
 | |
|                     p = n.serializedObject.FindProperty("MolocoSetting.iOS.interTestUnitID");
 | |
|                     p.stringValue = arr[1];
 | |
|                     p = n.serializedObject.FindProperty("MolocoSetting.iOS.rewardTestUnitID");
 | |
|                     p.stringValue = arr[2];
 | |
|                 }
 | |
|             }
 | |
|             
 | |
|             //----------- ADSettings -------------------
 | |
|             n = so.FindProperty("ADSetting");
 | |
|             if (null != n)
 | |
|             {
 | |
|                 p = n.serializedObject.FindProperty("ADSetting.SDK_KEY");
 | |
|                 p.stringValue = _serviceConfig.ad_settings.sdk_key;
 | |
|                 
 | |
|                 arr = _serviceConfig.ad_settings.max_ids_android;
 | |
|                 if(IsArrayHasLength(arr, 3))
 | |
|                 {
 | |
|                     p = n.serializedObject.FindProperty("ADSetting.Android_Banner_ID");
 | |
|                     p.stringValue = arr[0];
 | |
|                     p = n.serializedObject.FindProperty("ADSetting.Android_Interstitial_ID");
 | |
|                     p.stringValue = arr[1];
 | |
|                     p = n.serializedObject.FindProperty("ADSetting.Android_Rewarded_ID");
 | |
|                     p.stringValue = arr[2];
 | |
|                 }
 | |
|                 
 | |
|                 arr = _serviceConfig.ad_settings.max_ids_ios;
 | |
|                 if (IsArrayHasLength(arr, 3))
 | |
|                 {
 | |
|                     p = n.serializedObject.FindProperty("ADSetting.IOS_Banner_ID");
 | |
|                     p.stringValue = arr[0];
 | |
|                     p = n.serializedObject.FindProperty("ADSetting.IOS_Interstitial_ID");
 | |
|                     p.stringValue = arr[1];
 | |
|                     p = n.serializedObject.FindProperty("ADSetting.IOS_Rewarded_ID");
 | |
|                     p.stringValue = arr[2];
 | |
|                 }
 | |
|             }
 | |
|             
 | |
|             //----------- AdjustSetting -------------------
 | |
|             n = so.FindProperty("AdjustSetting");
 | |
|             if (null != n 
 | |
|                 && IsArrayHasLength(_serviceConfig.adjust_settings.app_token, 2))
 | |
|             {
 | |
|                 p = n.serializedObject.FindProperty("AdjustSetting.androidAppToken");
 | |
|                 p.stringValue = _serviceConfig.adjust_settings.app_token[0];
 | |
|                 
 | |
|                 p = n.serializedObject.FindProperty("AdjustSetting.iOSAppToken");
 | |
|                 p.stringValue = _serviceConfig.adjust_settings.app_token[1];
 | |
|             }
 | |
| 
 | |
|             //----------- AnalyticsSetting -------------------
 | |
|             n = so.FindProperty("AnalyticsSetting");
 | |
|             if (null != n)
 | |
|             {
 | |
|                 p = n.serializedObject.FindProperty("AnalyticsSetting.levelEndSuccessNum");
 | |
|                 p.intValue = _serviceConfig.app_settings.level_end_success_num;
 | |
|                 p = n.serializedObject.FindProperty("AnalyticsSetting.enalbeFirebaseAnalytics");
 | |
|                 p.boolValue = _serviceConfig.app_settings.enable_firebase;
 | |
|                 p = n.serializedObject.FindProperty("AnalyticsSetting.enalbeFacebookAnalytics");
 | |
|                 p.boolValue = _serviceConfig.app_settings.enable_facebook;
 | |
|                 p = n.serializedObject.FindProperty("AnalyticsSetting.enalbeAdjustAnalytics");
 | |
|                 p.boolValue = _serviceConfig.app_settings.enable_adjust;
 | |
|                 p = n.serializedObject.FindProperty("AnalyticsSetting.adjustEventList");
 | |
|                 if (null != p && IsArrayNotEmpty(_serviceConfig.adjust_settings.events))
 | |
|                 {
 | |
|                     p.ClearArray();
 | |
|                     for (int i = 0; i < _serviceConfig.adjust_settings.events.Length; i++)
 | |
|                     {
 | |
|                         arr = _serviceConfig.adjust_settings.events[i].Split(",");
 | |
|                         if (IsArrayHasLength(arr, 3))
 | |
|                         {
 | |
|                             p.InsertArrayElementAtIndex(i);
 | |
|                             nn = p.GetArrayElementAtIndex(i).serializedObject;
 | |
|                             nn.FindProperty($"AnalyticsSetting.adjustEventList.Array.data[{i}].EventName").stringValue = arr[0];
 | |
|                             nn.FindProperty($"AnalyticsSetting.adjustEventList.Array.data[{i}].AndroidToken").stringValue = arr[1];
 | |
|                             nn.FindProperty($"AnalyticsSetting.adjustEventList.Array.data[{i}].IOSToken").stringValue = arr[2];
 | |
|                         }
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|             
 | |
|             //---------------- Productions ------------------------
 | |
|             n = so.FindProperty("Products");
 | |
|             if (n != null && IsArrayNotEmpty(_serviceConfig.products))
 | |
|             {
 | |
|                 n.ClearArray();
 | |
|                 for (int i = 0; i < _serviceConfig.products.Length; i++)
 | |
|                 {
 | |
|                     arr = _serviceConfig.products[i].Split(",");
 | |
|                     if (IsArrayHasLength(arr, 5))
 | |
|                     {
 | |
|                         n.InsertArrayElementAtIndex(i);
 | |
|                         nn = n.GetArrayElementAtIndex(i).serializedObject;
 | |
|                         nn.FindProperty($"Products.Array.data[{i}].ProductName").stringValue = arr[0];
 | |
|                         nn.FindProperty($"Products.Array.data[{i}].GooglePlayProductId").stringValue = arr[1];
 | |
|                         nn.FindProperty($"Products.Array.data[{i}].AppStoreProductId").stringValue = arr[2];
 | |
|                         nn.FindProperty($"Products.Array.data[{i}].Price").doubleValue = double.Parse(arr[3]);
 | |
|                         nn.FindProperty($"Products.Array.data[{i}].Type").enumValueIndex = int.Parse(arr[4]);
 | |
|                         nn.FindProperty($"Products.Array.data[{i}].IsFree").boolValue = false;
 | |
|                         nn.FindProperty($"Products.Array.data[{i}].Category").stringValue = "Store";
 | |
|                     } 
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             //------- Save SO ----------
 | |
|             so.ApplyModifiedProperties();
 | |
|             EditorUtility.SetDirty(settings);
 | |
|             AssetDatabase.SaveAssetIfDirty(settings);
 | |
|         }
 | |
| 
 | |
|         //------------------------- AppLovinSettings --------------------------------
 | |
|         private void ImportAppLovinSettings()
 | |
|         {
 | |
|             EditorPrefs.SetBool(KeyMaxAutoUpdateEnabled, false); // 关闭Max自动升级功能
 | |
|             
 | |
|             AppLovinSettings settings = null;
 | |
|             if (IsAssetExists(nameof(AppLovinSettings), APPLOVIN_SETTINGS_PATH))
 | |
|             {
 | |
|                 settings = AssetDatabase.LoadAssetAtPath<AppLovinSettings>(APPLOVIN_SETTINGS_PATH);
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 settings = CreateInstance<AppLovinSettings>();
 | |
|                 AssetDatabase.CreateAsset(settings, APPLOVIN_SETTINGS_PATH);
 | |
|             }
 | |
| 
 | |
|             settings.SetAttributionReportEndpoint = true;
 | |
|             settings.QualityServiceEnabled = true;
 | |
|             settings.SdkKey = _serviceConfig.ad_settings.sdk_key;
 | |
|             if (IsArrayHasLength(_serviceConfig.ad_settings.admob_app_id, 2))
 | |
|             {
 | |
|                 settings.AdMobAndroidAppId = _serviceConfig.ad_settings.admob_app_id[0];
 | |
|                 settings.AdMobIosAppId = _serviceConfig.ad_settings.admob_app_id[1];
 | |
|             }
 | |
|             settings.ConsentFlowEnabled = false;
 | |
|             EditorUtility.SetDirty(settings);
 | |
|             AssetDatabase.SaveAssetIfDirty(settings);
 | |
|         }
 | |
| 
 | |
|         //------------------------- FacebookSettings --------------------------------
 | |
|         private void ImportFacebookSettings()
 | |
|         {
 | |
|             FacebookSettings settings = null;
 | |
|             if (IsAssetExists(nameof(FacebookSettings), FACEBOOK_SETTINGS_PATH))
 | |
|             {
 | |
|                 settings = AssetDatabase.LoadAssetAtPath<FacebookSettings>(FACEBOOK_SETTINGS_PATH);
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 settings = CreateInstance<FacebookSettings>();
 | |
|                 AssetDatabase.CreateAsset(settings, FACEBOOK_SETTINGS_PATH);
 | |
|             }
 | |
| 
 | |
|             var so = new SerializedObject(settings);
 | |
|             SerializedProperty n;
 | |
|             
 | |
|             n = so.FindProperty("appLabels");
 | |
|             if (n != null)
 | |
|             {
 | |
|                 n.ClearArray();
 | |
|                 n.InsertArrayElementAtIndex(0);
 | |
|                 n.GetArrayElementAtIndex(0).stringValue = _serviceConfig.app_settings.product_name;
 | |
|             }
 | |
| 
 | |
|             n = so.FindProperty("appIds");
 | |
|             if (n != null)
 | |
|             {
 | |
|                 n.ClearArray();
 | |
|                 n.InsertArrayElementAtIndex(0);
 | |
|                 n.GetArrayElementAtIndex(0).stringValue = _serviceConfig.fb_settings.app_id;
 | |
|             }
 | |
|             
 | |
|             n = so.FindProperty("clientTokens");
 | |
|             if (n != null)
 | |
|             {
 | |
|                 n.ClearArray();
 | |
|                 n.InsertArrayElementAtIndex(0);
 | |
|                 n.GetArrayElementAtIndex(0).stringValue = _serviceConfig.fb_settings.client_token;
 | |
|             }
 | |
|             
 | |
|             n = so.FindProperty("androidKeystorePath");
 | |
|             n.stringValue = ANDROID_KEYSTORE_PATH;
 | |
|             
 | |
|             so.ApplyModifiedProperties();
 | |
|             EditorUtility.SetDirty(settings);
 | |
|             AssetDatabase.SaveAssetIfDirty(settings);
 | |
|         }
 | |
| 
 | |
|         private void ApplyMods()
 | |
|         {
 | |
|             PlayerSettings.applicationIdentifier = _serviceConfig.app_settings.bundle_id; // 设置包名
 | |
| 
 | |
| #if UNITY_ANDROID
 | |
|             AndroidManifestMod.Apply();
 | |
|             AndroidProjectMod.Apply();
 | |
| #endif
 | |
|         }
 | |
| 
 | |
| 
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region GUI Utils
 | |
|         
 | |
| 
 | |
|         private void GUI_Color(Color color, Action content)
 | |
|         {
 | |
|             var c = GUI.color;
 | |
|             GUI.color = color;
 | |
|             content?.Invoke();
 | |
|             GUI.color = c;
 | |
|         }
 | |
| 
 | |
| 
 | |
| 
 | |
|         private void GUI_Button(string label, Action content, Color color, GUIStyle style = null, params GUILayoutOption[] options)
 | |
|         {
 | |
|             GUI_Color(color, ()=> GUI_Button(label, content, style, options));
 | |
|         }
 | |
|         private void GUI_Button(string label, Action content, GUIStyle style = null, params GUILayoutOption[] options)
 | |
|         {
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
|             if (style != null)
 | |
|             {
 | |
|                 if (GUILayout.Button(label,style, options))
 | |
|                 {
 | |
|                     content?.Invoke();
 | |
|                 }
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 if (GUILayout.Button(label, options))
 | |
|                 {
 | |
|                     content?.Invoke();
 | |
|                 }
 | |
|             }
 | |
| 
 | |
|             
 | |
|         }
 | |
| 
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region Utils
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 获取Assets路径
 | |
|         /// </summary>
 | |
|         /// <param name="filter"></param>
 | |
|         /// <returns></returns>
 | |
|         private static bool IsAssetExists(string typeName, string defaultPath)
 | |
|         {
 | |
|             bool result = false;
 | |
|             var guids = AssetDatabase.FindAssets($"t:{typeName}");
 | |
|             string p = "";
 | |
|             if (guids != null && guids.Length > 0)
 | |
|             {
 | |
|                 for (int i = 0; i < guids.Length; i++)
 | |
|                 {
 | |
|                     p = AssetDatabase.GUIDToAssetPath(guids[i]);
 | |
|                     if (File.Exists(p))
 | |
|                     {
 | |
|                         if (p == defaultPath)
 | |
|                         {
 | |
|                             result = true;
 | |
|                         }
 | |
|                         else
 | |
|                         {
 | |
|                             File.Delete(p);
 | |
|                         }
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|             return result;
 | |
|         }
 | |
| 
 | |
|         private static bool IsArrayNotEmpty(Array array)
 | |
|         {
 | |
|             if (array == null) return false;
 | |
|             if (array.Length == 0) return false;
 | |
|             return true;
 | |
|         }
 | |
| 
 | |
|         private static bool IsArrayHasLength(Array array, int length)
 | |
|         {
 | |
|             if(!IsArrayNotEmpty(array)) return false;
 | |
|             return array.Length >= length;
 | |
|         }
 | |
| 
 | |
| 
 | |
|         #endregion
 | |
|         
 | |
|     }
 | |
| } |