DragonECS-Unity/src/DebugUtils/Monitors/Editor/PipelineMonitorEditor.cs

186 lines
6.5 KiB
C#
Raw Normal View History

2024-03-10 06:19:20 +08:00
#if UNITY_EDITOR
using DCFApixels.DragonECS.RunnersCore;
using DCFApixels.DragonECS.Unity.Internal;
using System;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace DCFApixels.DragonECS.Unity.Editors
{
[CustomEditor(typeof(PipelineMonitor))]
internal class PipelineMonitorEditor : ExtendedEditor<PipelineMonitor>
2024-03-10 06:19:20 +08:00
{
private GUIStyle _headerStyle;
private GUIStyle _interfacesStyle;
private Color _interfaceColor = new Color(0.96f, 1f, 0.16f);
private GUIStyle systemsListStyle;
private void CopyToClipboard()
{
2024-10-09 01:54:48 +08:00
var all = Target.Pipeline.AllSystems;
string[] names = new string[all.Length];
for (int i = 0; i < all.Length; i++)
{
var system = all[i];
string name;
if (system is SystemsLayerMarkerSystem l)
{
name = $"[ {l.name} ]";
}
else
{
2024-10-09 01:54:48 +08:00
var meta = system.GetMeta();
MetaColor color;
if (meta.IsCustomColor)
{
color = meta.Color;
}
else
{
color = EcsGUI.SelectPanelColor(meta, i, -1).ToMetaColor();
}
name = $"{meta.Name} : {meta.TypeName} : {meta.MetaID} : {color.colorCode:X8}";
}
2024-10-09 01:54:48 +08:00
names[i] = name;
}
GUIUtility.systemCopyBuffer = string.Join("\r\n", names);
}
protected override void DrawCustom()
2024-03-10 06:19:20 +08:00
{
systemsListStyle = new GUIStyle(EditorStyles.miniLabel);
systemsListStyle.wordWrap = true;
if (Target.Pipeline == null || Target.Pipeline.IsDestoryed)
{
return;
}
if (_headerStyle == null)
{
_headerStyle = new GUIStyle(EditorStyles.boldLabel);
_interfacesStyle = new GUIStyle(EditorStyles.miniLabel);
_interfacesStyle.hover.textColor = _interfaceColor;
_interfacesStyle.focused.textColor = _interfaceColor;
_interfacesStyle.active.textColor = _interfaceColor;
_interfacesStyle.normal.textColor = _interfaceColor;
_interfacesStyle.wordWrap = true;
_headerStyle.fontSize = 28;
}
using (EcsGUI.Layout.BeginHorizontal())
{
GUILayout.Label("[Systems]", _headerStyle, GUILayout.ExpandWidth(true));
2024-10-09 01:54:48 +08:00
if (GUILayout.Button("Copy to Clipboard", GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
CopyToClipboard();
}
}
2024-03-10 06:19:20 +08:00
IsShowInterfaces = EditorGUILayout.Toggle("Show Interfaces", IsShowInterfaces);
IsShowHidden = EditorGUILayout.Toggle("Show Hidden", IsShowHidden);
using (EcsGUI.Layout.BeginVertical())
2024-03-10 06:19:20 +08:00
{
2024-10-19 01:08:29 +08:00
int i = 0;
foreach (var item in Target.Pipeline.AllSystems)
{
2024-10-19 01:08:29 +08:00
DrawSystem(item, i++);
}
2024-03-10 06:19:20 +08:00
}
GUILayout.Label("[Runners]", _headerStyle);
using (EcsGUI.Layout.BeginVertical(UnityEditorUtility.GetStyle(Color.black, 0.2f)))
2024-03-10 06:19:20 +08:00
{
2024-10-19 01:08:29 +08:00
int i = 0;
foreach (var item in Target.Pipeline.AllRunners)
2024-03-10 06:19:20 +08:00
{
if (item.Key.IsInterface == false)
{
2024-10-19 01:08:29 +08:00
DrawRunner(item.Value, i++);
}
2024-03-10 06:19:20 +08:00
}
}
}
2024-10-19 01:08:29 +08:00
private void DrawSystem(IEcsProcess system, int index)
2024-03-10 06:19:20 +08:00
{
if (system is SystemsLayerMarkerSystem markerSystem)
{
GUILayout.EndVertical();
GUILayout.BeginVertical(UnityEditorUtility.GetStyle(Color.black, 0.2f));
using (EcsGUI.Layout.BeginHorizontal()) using (var scope = EcsGUI.SetAlignment(GUI.skin.label))
2024-06-25 23:20:40 +08:00
{
scope.Target.alignment = TextAnchor.UpperLeft;
GUILayout.Label("<", GUILayout.ExpandWidth(true));
scope.Target.alignment = TextAnchor.UpperRight;
using (EcsGUI.SetAlpha(0.64f))
{
GUILayout.Label($"{markerSystem.layerNameSpace}", GUILayout.ExpandWidth(false));
}
2024-06-25 23:27:29 +08:00
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing * -4f);
2024-06-25 23:20:40 +08:00
scope.Target.alignment = TextAnchor.UpperLeft;
using (EcsGUI.SetFontStyle(scope.Target, FontStyle.Bold))
{
GUILayout.Label($"{markerSystem.layerName}", GUILayout.ExpandWidth(false));
}
scope.Target.alignment = TextAnchor.UpperRight;
GUILayout.Label(">", GUILayout.ExpandWidth(true));
}
2024-03-10 06:19:20 +08:00
return;
}
Type type = system.GetType();
TypeMeta meta = type.ToMeta();
if (CheckIsHidden(meta))
{
return;
}
string name = meta.Name;
2024-10-19 01:08:29 +08:00
Color color = EcsGUI.SelectPanelColor(meta, index, -1);
2024-03-10 06:19:20 +08:00
using (EcsGUI.Layout.BeginVertical(UnityEditorUtility.GetStyle(color, 0.2f)))
2024-03-10 06:19:20 +08:00
{
if (IsShowInterfaces)
{
GUILayout.Label(string.Join(", ", type.GetInterfaces().Select(o => o.Name)), _interfacesStyle);
}
GUILayout.Label(name, EditorStyles.boldLabel);
2024-03-10 06:19:20 +08:00
}
}
2024-10-19 01:08:29 +08:00
private void DrawRunner(IEcsRunner runner, int index)
2024-03-10 06:19:20 +08:00
{
Type type = runner.GetType();
TypeMeta meta = type.ToMeta();
if (CheckIsHidden(meta))
{
return;
}
2024-10-19 01:08:29 +08:00
Color color = EcsGUI.SelectPanelColor(meta, index, -1);
2024-03-10 06:19:20 +08:00
using (EcsGUI.Layout.BeginVertical(UnityEditorUtility.GetStyle(color, 0.2f)))
{
GUILayout.Label(meta.Name, EditorStyles.boldLabel);
GUILayout.Label(string.Join(", ", runner.ProcessRaw.Cast<object>().Select(o => o.GetType().Name)), systemsListStyle);
}
2024-03-10 06:19:20 +08:00
}
private bool CheckIsHidden(TypeMeta meta)
{
if (IsShowHidden)
return false;
return meta.IsHidden;
}
}
}
#endif