mirror of
https://github.com/DCFApixels/DragonECS-Unity.git
synced 2025-09-18 10:04:36 +08:00
add simple setting editor
This commit is contained in:
parent
22302ab443
commit
786c457b6a
107
src/Debug/Editor/SettingsEditor.cs
Normal file
107
src/Debug/Editor/SettingsEditor.cs
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#if UNITY_EDITOR
|
||||||
|
using System.Collections.Generic;
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DefineSymbolsInfo> _defineSymbols = null;
|
||||||
|
private void InitDefines()
|
||||||
|
{
|
||||||
|
string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
|
||||||
|
_defineSymbols = new List<DefineSymbolsInfo>()
|
||||||
|
{
|
||||||
|
nameof(EcsConsts.ENABLE_DRAGONECS_DEBUGGER),
|
||||||
|
nameof(EcsConsts.ENABLE_DRAGONECS_ASSERT_CHEKS),
|
||||||
|
nameof(EcsConsts.REFLECTION_DISABLED),
|
||||||
|
nameof(EcsConsts.DISABLE_DEBUG),
|
||||||
|
nameof(EcsConsts.ENABLE_DUMMY_SPAN),
|
||||||
|
nameof(EcsConsts.DISABLE_CATH_EXCEPTIONS),
|
||||||
|
nameof(EcsConsts.DISABLE_DRAGONECS_DEBUGGER),
|
||||||
|
"DEBUG",
|
||||||
|
};
|
||||||
|
for (int i = 0; i < _defineSymbols.Count; i++)
|
||||||
|
{
|
||||||
|
var symbol = _defineSymbols[i];
|
||||||
|
if (symbolsString.Contains(symbol.name))
|
||||||
|
{
|
||||||
|
symbol.isOn = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void OnGUI()
|
||||||
|
{
|
||||||
|
float labelWidth = EditorGUIUtility.labelWidth;
|
||||||
|
EditorGUIUtility.labelWidth *= 2f;
|
||||||
|
|
||||||
|
|
||||||
|
GUILayout.Label("Settings", EditorStyles.whiteLargeLabel);
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
Settings settings = new Settings();
|
||||||
|
settings.IsShowHidden = EditorGUILayout.Toggle(nameof(SettingsPrefs.IsShowHidden), SettingsPrefs.instance.IsShowHidden);
|
||||||
|
settings.IsShowInterfaces = EditorGUILayout.Toggle(nameof(SettingsPrefs.IsShowInterfaces), SettingsPrefs.instance.IsShowInterfaces);
|
||||||
|
settings.IsShowRuntimeComponents = EditorGUILayout.Toggle(nameof(SettingsPrefs.IsShowRuntimeComponents), SettingsPrefs.instance.IsShowRuntimeComponents);
|
||||||
|
if (EditorGUI.EndChangeCheck())
|
||||||
|
{
|
||||||
|
SettingsPrefs.instance.IsShowHidden = settings.IsShowHidden;
|
||||||
|
SettingsPrefs.instance.IsShowInterfaces = settings.IsShowInterfaces;
|
||||||
|
SettingsPrefs.instance.IsShowRuntimeComponents = settings.IsShowRuntimeComponents;
|
||||||
|
}
|
||||||
|
GUILayout.Label("Scripting Define Symbols", EditorStyles.whiteLargeLabel);
|
||||||
|
if (_defineSymbols == null)
|
||||||
|
{
|
||||||
|
InitDefines();
|
||||||
|
}
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
for (int i = 0; i < _defineSymbols.Count; i++)
|
||||||
|
{
|
||||||
|
var symbol = _defineSymbols[i];
|
||||||
|
symbol.isOn = EditorGUILayout.Toggle(symbol.name, symbol.isOn);
|
||||||
|
}
|
||||||
|
if (EditorGUI.EndChangeCheck()) { }
|
||||||
|
if (GUILayout.Button("Apply"))
|
||||||
|
{
|
||||||
|
string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
|
||||||
|
for (int i = 0; i < _defineSymbols.Count; i++)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
private struct Settings
|
||||||
|
{
|
||||||
|
public bool IsShowHidden;
|
||||||
|
public bool IsShowInterfaces;
|
||||||
|
public bool IsShowRuntimeComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
11
src/Debug/Editor/SettingsEditor.cs.meta
Normal file
11
src/Debug/Editor/SettingsEditor.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a8e3f83162b577840bd1f04cd59e11cb
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user