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

102 lines
4.1 KiB
C#
Raw Normal View History

2024-04-29 23:19:54 +08:00
#if UNITY_EDITOR
2025-03-13 15:48:29 +08:00
using DCFApixels.DragonECS.Unity.Internal;
using System.Collections.Generic;
2024-04-29 23:19:54 +08:00
using System.Linq;
using UnityEditor;
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();
}
2025-03-13 15:48:29 +08:00
private IEnumerable<DefinesUtility.Symbols> _defineSymbols = null;
2024-04-29 23:19:54 +08:00
private void InitDefines()
{
2025-03-13 15:48:29 +08:00
if (_defineSymbols != null) { return; }
_defineSymbols = DefinesUtility.LoadDefines(typeof(EcsDefines));
_defineSymbols = _defineSymbols.Concat(DefinesUtility.LoadDefines(typeof(EcsUnityDefines)));
2024-04-29 23:19:54 +08:00
}
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-11-06 20:38:49 +08:00
//float checkBoxWidth = 20f;
2024-05-01 00:30:56 +08:00
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())
{
2024-11-01 17:17:52 +08:00
prefs.IsShowHidden = EditorGUILayout.ToggleLeft(
UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsShowHidden)),
prefs.IsShowHidden);
2024-05-01 00:30:56 +08:00
2024-11-01 17:17:52 +08:00
prefs.IsShowInterfaces = EditorGUILayout.ToggleLeft(
UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsShowInterfaces)),
prefs.IsShowInterfaces);
2024-05-01 00:30:56 +08:00
2024-11-01 17:17:52 +08:00
prefs.IsShowRuntimeComponents = EditorGUILayout.ToggleLeft(
UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsShowRuntimeComponents)),
prefs.IsShowRuntimeComponents);
2024-05-01 00:30:56 +08:00
2024-11-01 17:17:52 +08:00
prefs.IsUseCustomNames = EditorGUILayout.ToggleLeft(
UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsUseCustomNames)),
prefs.IsUseCustomNames);
2024-12-10 20:34:15 +08:00
2024-12-15 17:01:55 +08:00
//prefs.IsFastModeRuntimeComponents = EditorGUILayout.ToggleLeft(
// UnityEditorUtility.TransformFieldName(nameof(UserSettingsPrefs.IsFastModeRuntimeComponents)),
// prefs.IsFastModeRuntimeComponents);
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-11-01 17:17:52 +08:00
{
2024-05-01 00:30:56 +08:00
GUILayout.BeginVertical(EditorStyles.helpBox);
2024-11-01 17:17:52 +08:00
}
2024-05-01 00:30:56 +08:00
//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);
2025-03-13 15:48:29 +08:00
InitDefines();
2024-04-29 23:19:54 +08:00
EditorGUI.BeginChangeCheck();
2025-03-13 15:48:29 +08:00
foreach (var symbol in _defineSymbols)
2024-04-29 23:19:54 +08:00
{
2025-03-13 15:48:29 +08:00
symbol.flag = EditorGUILayout.ToggleLeft(symbol.Name, symbol.flag);
2024-04-29 23:19:54 +08:00
}
2025-03-13 15:48:29 +08:00
2024-04-29 23:19:54 +08:00
if (EditorGUI.EndChangeCheck()) { }
if (GUILayout.Button("Apply"))
{
2025-03-13 15:48:29 +08:00
DefinesUtility.ApplyDefines(_defineSymbols);
2024-04-29 23:19:54 +08:00
InitDefines();
}
2024-05-01 00:30:56 +08:00
GUILayout.EndVertical();
2024-04-29 23:19:54 +08:00
EditorGUIUtility.labelWidth = labelWidth;
}
}
}
#endif