DragonECS-Unity/src/DebugUtils/Editor/SettingsEditor.cs

139 lines
6.2 KiB
C#
Raw Normal View History

2024-04-29 23:19:54 +08:00
#if UNITY_EDITOR
using System.Linq;
2024-09-08 21:36:24 +08:00
using System.Reflection;
2024-04-29 23:19:54 +08:00
using UnityEditor;
2024-06-13 19:03:36 +08:00
using UnityEditor.Build;
2024-04-29 23:19:54 +08:00
using UnityEngine;
namespace DCFApixels.DragonECS.Unity.Editors
{
public class SettingsEditor : EditorWindow
{
[MenuItem("Tools/" + EcsConsts.FRAMEWORK_NAME + "/Settings")]
static void Open()
{
var wnd = GetWindow<SettingsEditor>();
wnd.titleContent = new GUIContent($"{EcsConsts.FRAMEWORK_NAME} Settings");
wnd.Show();
}
2024-09-21 14:39:09 +08:00
private DefineSymbolsInfo[] _defineSymbols = null;
2024-04-29 23:19:54 +08:00
private void InitDefines()
{
2024-06-13 19:03:36 +08:00
string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.Standalone);
2024-09-21 14:39:09 +08:00
_defineSymbols =
typeof(EcsDefines).GetFields(BindingFlags.Static | BindingFlags.Public).Select(o => new DefineSymbolsInfo(o.Name, false))
.Concat(typeof(EcsUnityDefines).GetFields(BindingFlags.Static | BindingFlags.Public).Select(o => new DefineSymbolsInfo(o.Name, false)))
.ToArray();
for (int i = 0; i < _defineSymbols.Length; i++)
2024-04-29 23:19:54 +08:00
{
var symbol = _defineSymbols[i];
if (symbolsString.Contains(symbol.name))
{
symbol.isOn = true;
}
}
}
private void OnGUI()
{
2024-09-21 14:39:09 +08:00
var prefs = UserSettingsPrefs.instance;
2024-04-29 23:19:54 +08:00
float labelWidth = EditorGUIUtility.labelWidth;
2024-05-01 00:30:56 +08:00
EditorGUIUtility.labelWidth = 0f;
2024-04-29 23:19:54 +08:00
2024-05-01 00:30:56 +08:00
float checkBoxWidth = 20f;
GUILayout.Space(20f);
using (new EcsGUI.ColorScope(Color.white * 0.5f))
GUILayout.BeginVertical(EditorStyles.helpBox);
//using (new EcsGUI.ColorScope(Color.white * 1.2f))
2024-05-13 18:21:51 +08:00
GUILayout.Label("", EditorStyles.toolbar, GUILayout.ExpandWidth(true), GUILayout.Height(22f));
2024-05-01 00:30:56 +08:00
Rect rect = GUILayoutUtility.GetLastRect();
rect.xMin += 9f;
2024-09-21 14:39:09 +08:00
GUI.Label(rect, "User Settings", EditorStyles.whiteLargeLabel);
2024-04-29 23:19:54 +08:00
2024-06-13 18:04:47 +08:00
//using (prefs.DisableAutoSave())
{
GUILayout.BeginHorizontal();
prefs.IsShowHidden = EditorGUILayout.Toggle(prefs.IsShowHidden, GUILayout.Width(checkBoxWidth));
2024-09-21 14:39:09 +08:00
GUILayout.Label(UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsShowHidden)), GUILayout.ExpandWidth(false));
2024-06-13 18:04:47 +08:00
GUILayout.EndHorizontal();
2024-05-01 00:30:56 +08:00
2024-06-13 18:04:47 +08:00
GUILayout.BeginHorizontal();
prefs.IsShowInterfaces = EditorGUILayout.Toggle(prefs.IsShowInterfaces, GUILayout.Width(checkBoxWidth));
2024-09-21 14:39:09 +08:00
GUILayout.Label(UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsShowInterfaces)), GUILayout.ExpandWidth(false));
2024-06-13 18:04:47 +08:00
GUILayout.EndHorizontal();
2024-05-01 00:30:56 +08:00
2024-06-13 18:04:47 +08:00
GUILayout.BeginHorizontal();
prefs.IsShowRuntimeComponents = EditorGUILayout.Toggle(prefs.IsShowRuntimeComponents, GUILayout.Width(checkBoxWidth));
2024-09-21 14:39:09 +08:00
GUILayout.Label(UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsShowRuntimeComponents)), GUILayout.ExpandWidth(false));
2024-06-13 18:04:47 +08:00
GUILayout.EndHorizontal();
2024-05-01 00:30:56 +08:00
2024-06-13 18:04:47 +08:00
GUILayout.BeginHorizontal();
prefs.IsUseCustomNames = EditorGUILayout.Toggle(prefs.IsUseCustomNames, GUILayout.Width(checkBoxWidth));
2024-09-21 14:39:09 +08:00
GUILayout.Label(UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsUseCustomNames)), GUILayout.ExpandWidth(false));
2024-06-13 18:04:47 +08:00
GUILayout.EndHorizontal();
2024-05-15 00:36:56 +08:00
2024-09-21 14:39:09 +08:00
prefs.ComponentColorMode = (ComponentColorMode)EditorGUILayout.EnumPopup(UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.ComponentColorMode)), prefs.ComponentColorMode);
2024-04-29 23:19:54 +08:00
}
2024-05-01 00:30:56 +08:00
2024-06-13 18:04:47 +08:00
GUILayout.EndVertical();
2024-05-01 00:30:56 +08:00
GUILayout.Space(20f);
2024-06-13 18:04:47 +08:00
using (EcsGUI.SetColor(Color.white * 0.5f))
2024-05-01 00:30:56 +08:00
GUILayout.BeginVertical(EditorStyles.helpBox);
//using (new EcsGUI.ColorScope(Color.white * 1.2f))
2024-05-13 18:21:51 +08:00
GUILayout.Label("", EditorStyles.toolbar, GUILayout.ExpandWidth(true), GUILayout.Height(22f));
2024-05-01 00:30:56 +08:00
rect = GUILayoutUtility.GetLastRect();
rect.xMin += 9f;
GUI.Label(rect, "Scripting Define Symbols", EditorStyles.whiteLargeLabel);
2024-04-29 23:19:54 +08:00
if (_defineSymbols == null)
{
InitDefines();
}
EditorGUI.BeginChangeCheck();
2024-09-21 14:39:09 +08:00
for (int i = 0; i < _defineSymbols.Length; i++)
2024-04-29 23:19:54 +08:00
{
2024-05-01 00:30:56 +08:00
GUILayout.BeginHorizontal();
2024-04-29 23:19:54 +08:00
var symbol = _defineSymbols[i];
2024-05-01 00:30:56 +08:00
symbol.isOn = EditorGUILayout.Toggle(symbol.isOn, GUILayout.Width(checkBoxWidth));
2024-05-13 18:21:51 +08:00
if (symbol.name == "DEBUG")
2024-05-01 00:30:56 +08:00
{
GUILayout.Label(symbol.name + " (Build Olny)", GUILayout.ExpandWidth(false));
}
else
{
GUILayout.Label(symbol.name, GUILayout.ExpandWidth(false));
}
GUILayout.EndHorizontal();
2024-04-29 23:19:54 +08:00
}
if (EditorGUI.EndChangeCheck()) { }
if (GUILayout.Button("Apply"))
{
string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
2024-09-21 14:39:09 +08:00
for (int i = 0; i < _defineSymbols.Length; i++)
2024-04-29 23:19:54 +08:00
{
var symbol = _defineSymbols[i];
symbolsString = symbolsString.Replace(symbol.name, "");
}
symbolsString += ";" + string.Join(';', _defineSymbols.Where(o => o.isOn).Select(o => o.name));
PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, symbolsString);
InitDefines();
}
2024-05-01 00:30:56 +08:00
GUILayout.EndVertical();
2024-04-29 23:19:54 +08:00
EditorGUIUtility.labelWidth = labelWidth;
}
private class DefineSymbolsInfo
{
public string name;
public bool isOn;
public DefineSymbolsInfo(string name, bool isOn)
{
this.name = name;
this.isOn = isOn;
}
public static implicit operator DefineSymbolsInfo(string a) => new DefineSymbolsInfo(a, false);
}
}
}
#endif