2024-03-10 06:19:20 +08:00
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
using DCFApixels.DragonECS.Unity.Internal;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DCFApixels.DragonECS.Unity.Editors
|
|
|
|
|
|
{
|
|
|
|
|
|
[CustomEditor(typeof(PipelineProcessMonitor))]
|
2024-09-14 23:30:11 +08:00
|
|
|
|
internal class PipelineProcessesMonitorEditor : ExtendedEditor<PipelineProcessMonitor>
|
2024-03-10 06:19:20 +08:00
|
|
|
|
{
|
2024-03-10 08:10:58 +08:00
|
|
|
|
private static Type SYSTEM_INTERFACE_TYPE = typeof(IEcsProcess);
|
|
|
|
|
|
|
|
|
|
|
|
private List<ProcessData> _processList = new List<ProcessData>();
|
2024-03-10 06:19:20 +08:00
|
|
|
|
private Dictionary<Type, int> _processeIndexes = new Dictionary<Type, int>();
|
2024-03-10 08:10:58 +08:00
|
|
|
|
private SystemData[] _systemsList;
|
2024-03-10 06:19:20 +08:00
|
|
|
|
|
2024-09-14 23:30:11 +08:00
|
|
|
|
protected override void OnInit()
|
2024-03-10 06:19:20 +08:00
|
|
|
|
{
|
2024-03-10 08:10:58 +08:00
|
|
|
|
_processList.Clear();
|
2024-03-10 06:19:20 +08:00
|
|
|
|
_processeIndexes.Clear();
|
2024-03-10 08:10:58 +08:00
|
|
|
|
IEnumerable<IEcsProcess> fileretSystems = Target.Pipeline.AllSystems;
|
2024-03-10 06:19:20 +08:00
|
|
|
|
if (IsShowHidden)
|
2024-03-10 08:10:58 +08:00
|
|
|
|
{ fileretSystems = fileretSystems.Where(o => o is SystemsLayerMarkerSystem == false); }
|
2024-03-10 06:19:20 +08:00
|
|
|
|
else
|
2024-03-10 08:10:58 +08:00
|
|
|
|
{ fileretSystems = fileretSystems.Where(o => o.GetMeta().IsHidden == false); }
|
|
|
|
|
|
_systemsList = fileretSystems.Select(o => new SystemData(o.GetMeta(), o)).ToArray();
|
2024-03-10 06:19:20 +08:00
|
|
|
|
|
2024-03-10 08:10:58 +08:00
|
|
|
|
for (int i = 0; i < _systemsList.Length; i++)
|
2024-03-10 06:19:20 +08:00
|
|
|
|
{
|
2024-03-10 08:10:58 +08:00
|
|
|
|
var system = _systemsList[i];
|
|
|
|
|
|
foreach (var interfaceType in system.meta.Type.GetInterfaces())
|
2024-03-10 06:19:20 +08:00
|
|
|
|
{
|
2026-03-15 21:57:40 +08:00
|
|
|
|
TypeMeta meta = interfaceType.GetMeta();
|
2024-03-10 08:10:58 +08:00
|
|
|
|
if (SYSTEM_INTERFACE_TYPE.IsAssignableFrom(interfaceType) && SYSTEM_INTERFACE_TYPE != interfaceType && (IsShowHidden || meta.IsHidden == false))
|
2024-03-10 06:19:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
ProcessData data;
|
2024-03-10 08:10:58 +08:00
|
|
|
|
if (_processeIndexes.TryGetValue(interfaceType, out int index) == false)
|
2024-03-10 06:19:20 +08:00
|
|
|
|
{
|
2024-03-10 08:10:58 +08:00
|
|
|
|
index = _processList.Count;
|
2024-03-10 06:19:20 +08:00
|
|
|
|
_processeIndexes.Add(interfaceType, index);
|
|
|
|
|
|
|
|
|
|
|
|
data = new ProcessData();
|
2024-03-10 09:18:40 +08:00
|
|
|
|
data.meta = meta;
|
2024-03-10 08:10:58 +08:00
|
|
|
|
data.systemsBitMask = new BitMask(_systemsList.Length);
|
|
|
|
|
|
_processList.Add(data);
|
2024-03-10 06:19:20 +08:00
|
|
|
|
}
|
2024-03-10 08:10:58 +08:00
|
|
|
|
data = _processList[index];
|
2024-03-10 06:19:20 +08:00
|
|
|
|
data.systemsBitMask[i] = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private Vector2 _position;
|
|
|
|
|
|
private Vector2 _cellsize = new Vector2(EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight);
|
|
|
|
|
|
private Vector2 _nameCellSize = new Vector2(200f, 200f);
|
|
|
|
|
|
|
2024-03-10 09:18:40 +08:00
|
|
|
|
private (TypeMeta system, TypeMeta process) _selectedPointMeta = default;
|
2024-09-14 23:30:11 +08:00
|
|
|
|
|
|
|
|
|
|
protected override void DrawCustom()
|
2024-03-10 06:19:20 +08:00
|
|
|
|
{
|
2026-04-14 15:19:41 +08:00
|
|
|
|
using (DragonGUI.CheckChanged())
|
2024-03-10 06:19:20 +08:00
|
|
|
|
{
|
2024-09-14 23:30:11 +08:00
|
|
|
|
IsShowHidden = EditorGUILayout.Toggle("Show Hidden", IsShowHidden);
|
2026-04-14 15:19:41 +08:00
|
|
|
|
if (DragonGUI.Changed)
|
2024-09-14 23:30:11 +08:00
|
|
|
|
{
|
|
|
|
|
|
Init();
|
|
|
|
|
|
}
|
2024-03-10 06:19:20 +08:00
|
|
|
|
}
|
2024-09-14 23:30:11 +08:00
|
|
|
|
|
2024-03-10 06:19:20 +08:00
|
|
|
|
|
|
|
|
|
|
GUILayout.Label("", GUILayout.ExpandWidth(true), GUILayout.Height(400f));
|
2024-03-10 08:10:58 +08:00
|
|
|
|
Rect rect = GUILayoutUtility.GetLastRect();
|
2024-03-10 06:19:20 +08:00
|
|
|
|
|
|
|
|
|
|
rect.height = 400f;
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-10 08:10:58 +08:00
|
|
|
|
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));
|
2024-03-11 05:43:56 +08:00
|
|
|
|
//GUI.Button(rect, "", EditorStyles.helpBox);
|
2024-03-10 09:18:40 +08:00
|
|
|
|
|
2024-03-10 06:19:20 +08:00
|
|
|
|
_position = GUI.BeginScrollView(rect, _position, rectView, true, true);
|
|
|
|
|
|
|
|
|
|
|
|
Vector2 pivod = _nameCellSize;
|
2024-03-10 08:10:58 +08:00
|
|
|
|
rect = default;
|
2024-03-10 06:19:20 +08:00
|
|
|
|
rect.y = _nameCellSize.y;
|
|
|
|
|
|
rect.width = _nameCellSize.x;
|
|
|
|
|
|
rect.height = _cellsize.x;
|
|
|
|
|
|
rect.y -= _cellsize.y;
|
2024-03-10 08:10:58 +08:00
|
|
|
|
//processes line
|
|
|
|
|
|
for (int i = 0; i < _processList.Count; i++)
|
2024-03-10 06:19:20 +08:00
|
|
|
|
{
|
2024-03-10 09:18:40 +08:00
|
|
|
|
TypeMeta meta = _processList[i].meta;
|
2024-03-10 08:10:58 +08:00
|
|
|
|
Rect lineRect = rect;
|
2024-03-10 06:19:20 +08:00
|
|
|
|
lineRect.y = 0f;
|
|
|
|
|
|
lineRect.x = _nameCellSize.x + _cellsize.x * i;
|
|
|
|
|
|
lineRect.width = _cellsize.x;
|
|
|
|
|
|
lineRect.height = rectView.height;
|
2024-03-10 08:10:58 +08:00
|
|
|
|
lineRect = RectUtility.AddPadding(lineRect, 1, 0);
|
2024-03-10 09:18:40 +08:00
|
|
|
|
|
2024-03-10 08:10:58 +08:00
|
|
|
|
Color color = meta.Color.ToUnityColor();
|
|
|
|
|
|
color = NormalizeGridColor(i, color);
|
|
|
|
|
|
EditorGUI.DrawRect(lineRect, color);
|
2024-03-10 06:19:20 +08:00
|
|
|
|
|
2026-04-14 15:19:41 +08:00
|
|
|
|
if (DragonGUI.HitTest(lineRect))
|
2024-03-10 09:18:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
GUI.Button(lineRect, "", EditorStyles.selectionRect);
|
|
|
|
|
|
_selectedPointMeta.process = meta;
|
|
|
|
|
|
}
|
2024-03-10 06:19:20 +08:00
|
|
|
|
GUIUtility.RotateAroundPivot(90, pivod);
|
2024-03-10 08:10:58 +08:00
|
|
|
|
GUI.Label(rect, UnityEditorUtility.GetLabel(meta.Name), EditorStyles.miniBoldLabel);
|
2024-03-10 06:19:20 +08:00
|
|
|
|
GUIUtility.RotateAroundPivot(-90, pivod);
|
|
|
|
|
|
|
|
|
|
|
|
pivod.x += _cellsize.x;
|
|
|
|
|
|
rect.x += _cellsize.x;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 08:10:58 +08:00
|
|
|
|
rect = default;
|
2024-03-10 06:19:20 +08:00
|
|
|
|
rect.y = _nameCellSize.y;
|
|
|
|
|
|
rect.width = _nameCellSize.x;
|
|
|
|
|
|
rect.height = _cellsize.x;
|
2024-03-10 08:10:58 +08:00
|
|
|
|
//systems line
|
|
|
|
|
|
for (int i = 0; i < _systemsList.Length; i++)
|
2024-03-10 06:19:20 +08:00
|
|
|
|
{
|
2024-03-10 08:10:58 +08:00
|
|
|
|
TypeMeta meta = _systemsList[i].meta;
|
2024-03-10 06:19:20 +08:00
|
|
|
|
string name = meta.Name;
|
|
|
|
|
|
|
2024-03-10 08:10:58 +08:00
|
|
|
|
Rect lineRect = rect;
|
2024-03-10 06:19:20 +08:00
|
|
|
|
lineRect.width = rectView.width;
|
2024-03-10 08:10:58 +08:00
|
|
|
|
lineRect = RectUtility.AddPadding(lineRect, 0, 1);
|
2024-03-10 09:18:40 +08:00
|
|
|
|
|
2024-03-10 08:10:58 +08:00
|
|
|
|
Color color = meta.Color.ToUnityColor();
|
|
|
|
|
|
color = NormalizeGridColor(i, color);
|
|
|
|
|
|
EditorGUI.DrawRect(lineRect, color);
|
2024-03-10 06:19:20 +08:00
|
|
|
|
|
2026-04-14 15:19:41 +08:00
|
|
|
|
if (DragonGUI.HitTest(lineRect))
|
2024-03-10 09:18:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
GUI.Button(lineRect, "", EditorStyles.selectionRect);
|
|
|
|
|
|
_selectedPointMeta.system = meta;
|
|
|
|
|
|
}
|
2024-03-10 08:10:58 +08:00
|
|
|
|
GUI.Label(rect, UnityEditorUtility.GetLabel(name, i + " " + name), EditorStyles.miniBoldLabel);
|
2024-03-10 06:19:20 +08:00
|
|
|
|
rect.y += _cellsize.y;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 09:18:40 +08:00
|
|
|
|
Texture checkIcon = EditorGUIUtility.IconContent("DotFill").image;
|
|
|
|
|
|
|
2024-03-10 08:10:58 +08:00
|
|
|
|
//matrix
|
|
|
|
|
|
for (int x = 0; x < _processList.Count; x++)
|
2024-03-10 06:19:20 +08:00
|
|
|
|
{
|
2024-03-10 08:10:58 +08:00
|
|
|
|
var process = _processList[x];
|
|
|
|
|
|
for (int y = 0; y < _systemsList.Length; y++)
|
2024-03-10 06:19:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
rect = new Rect(x * _cellsize.x + _nameCellSize.x, y * _cellsize.y + _nameCellSize.y, _cellsize.x, _cellsize.y);
|
|
|
|
|
|
bool flag = process.systemsBitMask[y];
|
2024-03-10 09:18:40 +08:00
|
|
|
|
if (flag)
|
|
|
|
|
|
{
|
|
|
|
|
|
GUI.Label(rect, UnityEditorUtility.GetLabel(checkIcon));
|
|
|
|
|
|
}
|
2024-03-10 06:19:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
GUI.EndScrollView();
|
2024-03-10 09:18:40 +08:00
|
|
|
|
|
|
|
|
|
|
Rect r = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, EditorGUIUtility.singleLineHeight);
|
2024-03-10 10:20:44 +08:00
|
|
|
|
if (_selectedPointMeta.process != null && _selectedPointMeta.system != null)
|
2024-03-10 09:18:40 +08:00
|
|
|
|
{
|
|
|
|
|
|
GUI.Label(r, $"{_selectedPointMeta.process.Name}-{_selectedPointMeta.system.Name}");
|
|
|
|
|
|
}
|
2024-03-10 06:19:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-10 08:10:58 +08:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-10 06:19:20 +08:00
|
|
|
|
private class ProcessData
|
|
|
|
|
|
{
|
2024-03-10 09:18:40 +08:00
|
|
|
|
public TypeMeta meta;
|
2024-03-10 06:19:20 +08:00
|
|
|
|
public BitMask systemsBitMask;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|