From 3f75ec5f981d295c366a61ee5312fa17fa404a87 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sun, 10 Mar 2024 08:10:58 +0800 Subject: [PATCH] update style --- .../Monitors/Editor/PipelineMonitorEditor.cs | 13 -- .../Editor/PipelineProcessesMonitorEditor.cs | 137 ++++++++++-------- src/Internal/Editor/UnityEditorUtility.cs | 8 + src/Internal/Utils/ColorUtility.cs | 2 +- 4 files changed, 84 insertions(+), 76 deletions(-) diff --git a/src/Debug/Monitors/Editor/PipelineMonitorEditor.cs b/src/Debug/Monitors/Editor/PipelineMonitorEditor.cs index ccc2bcc..41819f6 100644 --- a/src/Debug/Monitors/Editor/PipelineMonitorEditor.cs +++ b/src/Debug/Monitors/Editor/PipelineMonitorEditor.cs @@ -77,7 +77,6 @@ namespace DCFApixels.DragonECS.Unity.Editors } GUILayout.EndVertical(); } - private void DrawSystem(IEcsProcess system) { if (system is SystemsLayerMarkerSystem markerSystem) @@ -112,7 +111,6 @@ namespace DCFApixels.DragonECS.Unity.Editors GUILayout.Label(name, EditorStyles.boldLabel); GUILayout.EndVertical(); } - private void DrawRunner(IEcsRunner runner) { Type type = runner.GetType(); @@ -122,8 +120,6 @@ namespace DCFApixels.DragonECS.Unity.Editors { return; } - - //Color color = (GetAttribute(type) ?? _fakeDebugColorAttribute).GetUnityColor(); Color color = meta.Color.ToUnityColor(); GUILayout.BeginVertical(UnityEditorUtility.GetStyle(color, 0.2f)); @@ -131,15 +127,6 @@ namespace DCFApixels.DragonECS.Unity.Editors GUILayout.Label(string.Join(", ", runner.ProcessRaw.Cast().Select(o => o.GetType().Name)), systemsListStyle); GUILayout.EndVertical(); } - - private TAttribute GetAttribute(Type target) where TAttribute : Attribute - { - var result = target.GetCustomAttributes(_debugColorAttributeType, false); - if (result.Length > 0) - return (TAttribute)result[0]; - return null; - } - private bool CheckIsHidden(TypeMeta meta) { if (IsShowHidden) diff --git a/src/Debug/Monitors/Editor/PipelineProcessesMonitorEditor.cs b/src/Debug/Monitors/Editor/PipelineProcessesMonitorEditor.cs index a7606aa..7c7e34a 100644 --- a/src/Debug/Monitors/Editor/PipelineProcessesMonitorEditor.cs +++ b/src/Debug/Monitors/Editor/PipelineProcessesMonitorEditor.cs @@ -12,11 +12,12 @@ namespace DCFApixels.DragonECS.Unity.Editors [CustomEditor(typeof(PipelineProcessMonitor))] internal class PipelineProcessesMonitorEditor : Editor { + private static Type SYSTEM_INTERFACE_TYPE = typeof(IEcsProcess); + private bool _isInit = false; - private List _processesList = new List(); + private List _processList = new List(); private Dictionary _processeIndexes = new Dictionary(); - private Type systemInterfaceType = typeof(IEcsProcess); - private IEcsProcess[] _systems; + private SystemData[] _systemsList; private PipelineProcessMonitor Target => (PipelineProcessMonitor)target; private bool IsShowInterfaces @@ -37,45 +38,39 @@ namespace DCFApixels.DragonECS.Unity.Editors return; } - _processesList.Clear(); + _processList.Clear(); _processeIndexes.Clear(); + IEnumerable fileretSystems = Target.Pipeline.AllSystems; if (IsShowHidden) - { - _systems = Target.Pipeline.AllSystems.Where(o => o is SystemsLayerMarkerSystem == false).ToArray(); - } + { fileretSystems = fileretSystems.Where(o => o is SystemsLayerMarkerSystem == false); } else - { - _systems = Target.Pipeline.AllSystems.Where(o => o.GetMeta().IsHidden == false).ToArray(); - } + { fileretSystems = fileretSystems.Where(o => o.GetMeta().IsHidden == false); } + _systemsList = fileretSystems.Select(o => new SystemData(o.GetMeta(), o)).ToArray(); - int i = 0; - foreach (var system in _systems) + for (int i = 0; i < _systemsList.Length; i++) { - foreach (var interfaceType in system.GetType().GetInterfaces()) + var system = _systemsList[i]; + foreach (var interfaceType in system.meta.Type.GetInterfaces()) { TypeMeta meta = interfaceType.ToMeta(); - if (systemInterfaceType.IsAssignableFrom(interfaceType) && systemInterfaceType != interfaceType && (IsShowHidden || meta.IsHidden == false)) + if (SYSTEM_INTERFACE_TYPE.IsAssignableFrom(interfaceType) && SYSTEM_INTERFACE_TYPE != interfaceType && (IsShowHidden || meta.IsHidden == false)) { ProcessData data; - if (!_processeIndexes.TryGetValue(interfaceType, out int index)) + if (_processeIndexes.TryGetValue(interfaceType, out int index) == false) { - index = _processesList.Count; + index = _processList.Count; _processeIndexes.Add(interfaceType, index); data = new ProcessData(); - _processesList.Add(data); - - data.name = meta.Name; - data.interfaceType = interfaceType; - data.systemsBitMask = new BitMask(_systems.Length); + data.interfaceMeta = meta; + data.systemsBitMask = new BitMask(_systemsList.Length); + _processList.Add(data); } - data = _processesList[index]; + data = _processList[index]; data.systemsBitMask[i] = true; } } - i++; } - _isInit = true; } private Vector2 _position; @@ -90,94 +85,112 @@ namespace DCFApixels.DragonECS.Unity.Editors { _isInit = false; } - Init(); - Rect rect; - Rect lineRect; GUILayout.Label("", GUILayout.ExpandWidth(true), GUILayout.Height(400f)); - rect = GUILayoutUtility.GetLastRect(); + Rect rect = GUILayoutUtility.GetLastRect(); rect.height = 400f; - Rect rectView = new Rect(0f, 0f, _nameCellSize.x + _cellsize.x * _processesList.Count, _nameCellSize.y + _cellsize.y * _systems.Length); + Rect rectView = new Rect(0f, 0f, _nameCellSize.x + _cellsize.x * _processList.Count, _nameCellSize.y + _cellsize.y * _systemsList.Length); + EditorGUI.DrawRect(rect, new Color(0, 0, 0, 0.6f)); _position = GUI.BeginScrollView(rect, _position, rectView, true, true); - - List systeNames = new List(); - - var blackStyle = UnityEditorUtility.GetStyle(Color.black, 0.04f); - var whiteStyle = UnityEditorUtility.GetStyle(Color.white, 0.04f); - GUIContent label = new GUIContent(); - + //var blackStyle = UnityEditorUtility.GetStyle(Color.black, 0.04f); + //var whiteStyle = UnityEditorUtility.GetStyle(Color.white, 0.04f); Vector2 pivod = _nameCellSize; - rect = new Rect(); + rect = default; rect.y = _nameCellSize.y; rect.width = _nameCellSize.x; rect.height = _cellsize.x; rect.y -= _cellsize.y; - for (int i = 0; i < _processesList.Count; i++) + //processes line + for (int i = 0; i < _processList.Count; i++) { - lineRect = rect; + TypeMeta meta = _processList[i].interfaceMeta; + Rect lineRect = rect; lineRect.y = 0f; lineRect.x = _nameCellSize.x + _cellsize.x * i; lineRect.width = _cellsize.x; lineRect.height = rectView.height; - GUI.Label(lineRect, "", i % 2 == 1 ? whiteStyle : blackStyle); + lineRect = RectUtility.AddPadding(lineRect, 1, 0); + //GUI.Label(lineRect, "", i % 2 == 1 ? whiteStyle : blackStyle); + Color color = meta.Color.ToUnityColor(); + color = NormalizeGridColor(i, color); + EditorGUI.DrawRect(lineRect, color); GUIUtility.RotateAroundPivot(90, pivod); - label.text = _processesList[i].name; - label.tooltip = "." + _processesList[i].name; - GUI.Label(rect, label, EditorStyles.miniBoldLabel); + GUI.Label(rect, UnityEditorUtility.GetLabel(meta.Name), EditorStyles.miniBoldLabel); GUIUtility.RotateAroundPivot(-90, pivod); pivod.x += _cellsize.x; rect.x += _cellsize.x; } - rect = new Rect(); + rect = default; rect.y = _nameCellSize.y; rect.width = _nameCellSize.x; rect.height = _cellsize.x; - for (int i = 0; i < _systems.Length; i++) + //systems line + for (int i = 0; i < _systemsList.Length; i++) { - TypeMeta meta = _systems[i].GetMeta(); + TypeMeta meta = _systemsList[i].meta; string name = meta.Name; - systeNames.Add(name); - lineRect = rect; + Rect lineRect = rect; lineRect.width = rectView.width; - GUI.Label(lineRect, "", i % 2 == 1 ? whiteStyle : blackStyle); + lineRect = RectUtility.AddPadding(lineRect, 0, 1); + //GUI.Label(lineRect, "", i % 2 == 1 ? whiteStyle : blackStyle); + Color color = meta.Color.ToUnityColor(); + color = NormalizeGridColor(i, color); + EditorGUI.DrawRect(lineRect, color); - label.text = name; - label.tooltip = i + " " + name; - GUI.Label(rect, label, EditorStyles.miniBoldLabel); + GUI.Label(rect, UnityEditorUtility.GetLabel(name, i + " " + name), EditorStyles.miniBoldLabel); rect.y += _cellsize.y; } - for (int x = 0; x < _processesList.Count; x++) + //matrix + for (int x = 0; x < _processList.Count; x++) { - var process = _processesList[x]; - for (int y = 0; y < _systems.Length; y++) + var process = _processList[x]; + for (int y = 0; y < _systemsList.Length; y++) { - string systemName = systeNames[x]; rect = new Rect(x * _cellsize.x + _nameCellSize.x, y * _cellsize.y + _nameCellSize.y, _cellsize.x, _cellsize.y); bool flag = process.systemsBitMask[y]; string labeltext = flag ? "^" : " "; - label.text = labeltext; - label.tooltip = $"{process.name}-{systemName}"; - GUI.Label(rect, label); + GUI.Label(rect, UnityEditorUtility.GetLabel(labeltext, $"{process.interfaceMeta.Name}-{_systemsList[x].meta.Name}")); } } - GUI.EndScrollView(); } + private static Color NormalizeGridColor(int index, Color color) + { + if (index % 2 == 1) + { + color = color / 1.4f; + color.a = 0.3f; + } + else + { + color.a = 0.5f; + } + return color; + } + private class SystemData + { + public TypeMeta meta; + public IEcsProcess system; + public SystemData(TypeMeta meta, IEcsProcess system) + { + this.meta = meta; + this.system = system; + } + } private class ProcessData { - public Type interfaceType; - public string name; + public TypeMeta interfaceMeta; public BitMask systemsBitMask; } } diff --git a/src/Internal/Editor/UnityEditorUtility.cs b/src/Internal/Editor/UnityEditorUtility.cs index 9a9f2f9..eb0eeb5 100644 --- a/src/Internal/Editor/UnityEditorUtility.cs +++ b/src/Internal/Editor/UnityEditorUtility.cs @@ -105,6 +105,14 @@ namespace DCFApixels.DragonECS.Unity.Editors #endregion #region Label + public static GUIContent GetLabelTemp() + { + if (_singletonContent == null) + { + _singletonContent = new GUIContent(); + } + return _singletonContent; + } public static GUIContent GetLabel(string name, string tooltip = null) { if (_singletonContent == null) diff --git a/src/Internal/Utils/ColorUtility.cs b/src/Internal/Utils/ColorUtility.cs index ca9f91d..fe2b945 100644 --- a/src/Internal/Utils/ColorUtility.cs +++ b/src/Internal/Utils/ColorUtility.cs @@ -14,7 +14,7 @@ namespace DCFApixels.DragonECS.Unity.Internal r = r + (gray - r) * (1 - t); g = g + (gray - g) * (1 - t); b = b + (gray - b) * (1 - t); - return new Color(r, g, b); + return new Color(r, g, b, self.a); } } } \ No newline at end of file