using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using UnityEditor; public class MacroSetting : EditorWindow { /// <summary> /// 宏分类 /// </summary> public enum MacroItemType { None, Develop, Product, A, B } /// <summary> /// 宏批量选择按钮 /// </summary> private void AddButton () { if (GUILayout.Button ("A组", GUILayout.Width (100))) { MultiChoice (MacroItemType.A); } if (GUILayout.Button ("B组", GUILayout.Width (100))) { MultiChoice (MacroItemType.B); } } /// <summary> /// 宏列表 /// </summary> private void AddMacroItem () { ls.Add (new MacroItem () { macroName = "LOCAL_RES", macroDispalyName = "使用本地资源", type = MacroItemType.Develop }); ls.Add (new MacroItem () { macroName = "Dev_Jp", macroDispalyName = "使用日本服务器", type = MacroItemType.Product }); ls.Add (new MacroItem () { macroName = "A1", macroDispalyName = "A1", type = MacroItemType.A }); ls.Add (new MacroItem () { macroName = "A2", macroDispalyName = "A2", type = MacroItemType.A }); ls.Add (new MacroItem () { macroName = "A3", macroDispalyName = "A3", type = MacroItemType.A }); ls.Add (new MacroItem () { macroName = "B1", macroDispalyName = "B1", type = MacroItemType.B }); ls.Add (new MacroItem () { macroName = "B2", macroDispalyName = "B2", type = MacroItemType.B }); ls.Add (new MacroItem () { macroName = "B3", macroDispalyName = "B3", type = MacroItemType.B }); } #region 不需要改动 class MacroItem { public string macroName; public string macroDispalyName; public MacroItemType type; } private List<MacroItem> ls = new List<MacroItem> (); private Dictionary<string, bool> dic = new Dictionary<string, bool> (); public string macroNameStr; [MenuItem ("Tools/MacroSetting")] public static void Settings () { MacroSetting sw = (MacroSetting)EditorWindow.GetWindow (typeof(MacroSetting)); sw.titleContent = new GUIContent ("宏设置"); sw.Show (); } void OnEnable () { #if UNITY_ANDROID macroNameStr = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android); #elif UNITY_IPHONE macroNameStr = PlayerSettings.GetScriptingDefineSymbolsForGroup (BuildTargetGroup.iOS); #elif UNITY_STANDALONE_WIN||UNITY_STANDALONE_OSX macroNameStr = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone); #endif } public MacroSetting () { ls.Clear (); AddMacroItem (); for (int i = 0; i < ls.Count; i++) { if (!string.IsNullOrEmpty (macroNameStr) && macroNameStr.IndexOf (ls [i].macroName) != -1) { dic [ls [i].macroName] = true; } else { dic [ls [i].macroName] = false; } } } private void OnGUI () { for (int i = 0; i < ls.Count; i++) { EditorGUILayout.BeginHorizontal ("box"); dic [ls [i].macroName] = GUILayout.Toggle (dic [ls [i].macroName], ls [i].macroDispalyName); EditorGUILayout.EndHorizontal (); } GUILayout.Label ("宏批量选择"); EditorGUILayout.BeginHorizontal (); AddButton (); EditorGUILayout.EndHorizontal (); if (GUILayout.Button ("保存宏", GUILayout.Width (100))) { SaveMacro (); } } private void MultiChoice (MacroItemType type) { for (int i = 0; i < ls.Count; i++) { if (ls [i].type == type) { dic [ls [i].macroName] = true; } else { dic [ls [i].macroName] = false; } } } private void SaveMacro () { macroNameStr = string.Empty; foreach (var item in dic) { if (item.Value) { macroNameStr += string.Format ("{0};", item.Key); } } PlayerSettings.SetScriptingDefineSymbolsForGroup (BuildTargetGroup.Android, macroNameStr); PlayerSettings.SetScriptingDefineSymbolsForGroup (BuildTargetGroup.iOS, macroNameStr); PlayerSettings.SetScriptingDefineSymbolsForGroup (BuildTargetGroup.Standalone, macroNameStr); //Close(); } #endregion }
宏管理
最新推荐文章于 2023-11-23 23:12:16 发布