2023-04-03 06:42:06 +08:00
|
|
|
|
using DCFApixels.DragonECS.Unity;
|
|
|
|
|
using DCFApixels.DragonECS.Unity.Debug;
|
2023-03-30 20:49:10 +08:00
|
|
|
|
using System.Reflection;
|
2023-03-26 11:20:02 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
2023-03-29 19:58:58 +08:00
|
|
|
|
namespace DCFApixels.DragonECS
|
2023-03-26 11:20:02 +08:00
|
|
|
|
{
|
2023-03-29 15:48:18 +08:00
|
|
|
|
[DebugHide, DebugColor(DebugColor.Gray)]
|
2023-03-30 05:33:35 +08:00
|
|
|
|
public class PipelineDebugSystem : IEcsPreInitSystem
|
2023-03-26 11:20:02 +08:00
|
|
|
|
{
|
2023-03-30 20:49:10 +08:00
|
|
|
|
private string _monitorName;
|
|
|
|
|
public PipelineDebugSystem(string monitorName = "Pipeline")
|
2023-03-26 11:20:02 +08:00
|
|
|
|
{
|
2023-03-30 20:49:10 +08:00
|
|
|
|
_monitorName = monitorName;
|
2023-03-26 11:20:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-30 05:33:35 +08:00
|
|
|
|
void IEcsPreInitSystem.PreInit(EcsPipeline pipeline)
|
2023-03-26 11:20:02 +08:00
|
|
|
|
{
|
2023-04-03 06:42:06 +08:00
|
|
|
|
PipelineDebugMonitor monitor = new GameObject(EcsConsts.DEBUG_PREFIX + _monitorName).AddComponent<PipelineDebugMonitor>();
|
2023-03-26 11:20:02 +08:00
|
|
|
|
monitor.source = this;
|
2023-03-30 05:33:35 +08:00
|
|
|
|
monitor.pipeline = pipeline;
|
2023-03-30 20:49:10 +08:00
|
|
|
|
monitor.monitorName = _monitorName;
|
2023-04-03 06:42:06 +08:00
|
|
|
|
|
|
|
|
|
//foreach (var item in pipeline.AllSystems) //Вырезано пока не сделаю TODO в SystemDebugMonitor
|
|
|
|
|
//{
|
|
|
|
|
// DebugNameAttribute debugName = item.GetType().GetCustomAttribute<DebugNameAttribute>();
|
|
|
|
|
// string name = debugName == null ? item.GetType().Name : debugName.name;
|
|
|
|
|
// SystemDebugMonitor.CreateMonitor(monitor.transform, item, name);
|
|
|
|
|
//}
|
2023-03-26 11:20:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-03 06:42:06 +08:00
|
|
|
|
public class PipelineDebugMonitor : DebugMonitorBase
|
2023-03-26 11:20:02 +08:00
|
|
|
|
{
|
2023-03-30 05:33:35 +08:00
|
|
|
|
internal PipelineDebugSystem source;
|
|
|
|
|
internal EcsPipeline pipeline;
|
2023-03-26 11:20:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
namespace Editors
|
|
|
|
|
{
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
2023-04-03 06:42:06 +08:00
|
|
|
|
[CustomEditor(typeof(PipelineDebugMonitor))]
|
2023-03-30 05:33:35 +08:00
|
|
|
|
public class PipelineDebugMonitorEditor : Editor
|
2023-03-26 11:20:02 +08:00
|
|
|
|
{
|
|
|
|
|
private DebugColorAttribute _fakeDebugColorAttribute = new DebugColorAttribute(DebugColor.White);
|
|
|
|
|
private Type _debugColorAttributeType = typeof(DebugColorAttribute);
|
|
|
|
|
private GUIStyle _headerStyle;
|
|
|
|
|
private GUIStyle _interfacesStyle;
|
|
|
|
|
private Color _interfaceColor = new Color(0.96f, 1f, 0.16f);
|
2023-04-03 06:42:06 +08:00
|
|
|
|
private PipelineDebugMonitor Target => (PipelineDebugMonitor)target;
|
2023-03-26 11:20:02 +08:00
|
|
|
|
public override void OnInspectorGUI()
|
|
|
|
|
{
|
|
|
|
|
if (Target.source == null)
|
|
|
|
|
return;
|
2023-03-27 20:49:27 +08:00
|
|
|
|
if (_headerStyle == null)
|
2023-03-26 11:20:02 +08:00
|
|
|
|
{
|
|
|
|
|
_headerStyle = new GUIStyle(EditorStyles.boldLabel);
|
2023-03-29 15:48:18 +08:00
|
|
|
|
_interfacesStyle = new GUIStyle(EditorStyles.miniLabel);
|
2023-03-26 11:20:02 +08:00
|
|
|
|
_interfacesStyle.hover.textColor = _interfaceColor;
|
|
|
|
|
_interfacesStyle.focused.textColor = _interfaceColor;
|
|
|
|
|
_interfacesStyle.active.textColor = _interfaceColor;
|
|
|
|
|
_interfacesStyle.normal.textColor = _interfaceColor;
|
|
|
|
|
_headerStyle.fontSize = 28;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GUILayout.Label("[Systems]", _headerStyle);
|
|
|
|
|
|
2023-03-30 20:49:10 +08:00
|
|
|
|
DebugMonitorPrefs.instance.IsShowInterfaces = EditorGUILayout.Toggle("Show Interfaces", DebugMonitorPrefs.instance.IsShowInterfaces);
|
2023-03-29 19:58:58 +08:00
|
|
|
|
DebugMonitorPrefs.instance.IsShowHidden = EditorGUILayout.Toggle("Show Hidden", DebugMonitorPrefs.instance.IsShowHidden);
|
2023-03-26 11:20:02 +08:00
|
|
|
|
|
2023-03-27 20:49:27 +08:00
|
|
|
|
GUILayout.BeginVertical();
|
2023-03-30 05:33:35 +08:00
|
|
|
|
foreach (var item in Target.pipeline.AllSystems)
|
2023-03-26 11:20:02 +08:00
|
|
|
|
{
|
|
|
|
|
DrawSystem(item);
|
|
|
|
|
}
|
2023-03-27 20:49:27 +08:00
|
|
|
|
GUILayout.EndVertical();
|
2023-03-26 11:20:02 +08:00
|
|
|
|
|
2023-03-29 15:48:18 +08:00
|
|
|
|
|
2023-03-26 11:20:02 +08:00
|
|
|
|
GUILayout.Label("[Runners]", _headerStyle);
|
|
|
|
|
|
2023-03-30 20:49:10 +08:00
|
|
|
|
GUILayout.BeginVertical(EcsEditor.GetStyle(Color.black, 0.2f));
|
2023-03-30 05:33:35 +08:00
|
|
|
|
foreach (var item in Target.pipeline.AllRunners)
|
2023-03-26 11:20:02 +08:00
|
|
|
|
{
|
|
|
|
|
DrawRunner(item.Value);
|
|
|
|
|
}
|
2023-03-29 15:48:18 +08:00
|
|
|
|
GUILayout.EndVertical();
|
2023-03-26 11:20:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawSystem(IEcsSystem system)
|
|
|
|
|
{
|
2023-03-27 20:49:27 +08:00
|
|
|
|
if(system is SystemsBlockMarkerSystem markerSystem)
|
|
|
|
|
{
|
|
|
|
|
GUILayout.EndVertical();
|
2023-03-30 20:49:10 +08:00
|
|
|
|
GUILayout.BeginVertical(EcsEditor.GetStyle(Color.black, 0.2f));
|
2023-03-27 20:49:27 +08:00
|
|
|
|
|
|
|
|
|
GUILayout.BeginHorizontal();
|
|
|
|
|
GUILayout.Label("<");
|
|
|
|
|
GUILayout.Label($"{markerSystem.name}", EditorStyles.boldLabel);
|
|
|
|
|
GUILayout.Label(">", GUILayout.ExpandWidth(false));
|
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-26 11:20:02 +08:00
|
|
|
|
Type type = system.GetType();
|
2023-03-29 15:48:18 +08:00
|
|
|
|
|
|
|
|
|
if (CheckIsHidden(type))
|
|
|
|
|
return;
|
|
|
|
|
|
2023-03-26 11:20:02 +08:00
|
|
|
|
string name = type.Name;
|
|
|
|
|
Color color = (GetAttribute<DebugColorAttribute>(type) ?? _fakeDebugColorAttribute).GetUnityColor();
|
|
|
|
|
|
2023-03-30 20:49:10 +08:00
|
|
|
|
GUILayout.BeginVertical(EcsEditor.GetStyle(color, 0.2f));
|
|
|
|
|
if (DebugMonitorPrefs.instance.IsShowInterfaces)
|
2023-03-26 11:20:02 +08:00
|
|
|
|
{
|
|
|
|
|
GUILayout.Label(string.Join(", ", type.GetInterfaces().Select(o => o.Name)), _interfacesStyle);
|
|
|
|
|
}
|
|
|
|
|
GUILayout.Label(name, EditorStyles.boldLabel);
|
|
|
|
|
GUILayout.EndVertical();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawRunner(IEcsRunner runner)
|
|
|
|
|
{
|
|
|
|
|
Type type = runner.GetType();
|
2023-03-29 15:48:18 +08:00
|
|
|
|
if (CheckIsHidden(type))
|
|
|
|
|
return;
|
|
|
|
|
|
2023-03-26 11:20:02 +08:00
|
|
|
|
Color color = (GetAttribute<DebugColorAttribute>(type) ?? _fakeDebugColorAttribute).GetUnityColor();
|
2023-03-30 20:49:10 +08:00
|
|
|
|
GUILayout.BeginVertical(EcsEditor.GetStyle(color, 0.2f));
|
2023-03-26 11:20:02 +08:00
|
|
|
|
GUILayout.Label(type.Name, EditorStyles.boldLabel);
|
2023-03-31 14:58:50 +08:00
|
|
|
|
GUILayout.Label(string.Join(", ", runner.Targets.Cast<object>().Select(o => o.GetType().Name)), EditorStyles.miniLabel);
|
2023-03-26 11:20:02 +08:00
|
|
|
|
GUILayout.EndVertical();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TAttribute GetAttribute<TAttribute>(Type target) where TAttribute : Attribute
|
|
|
|
|
{
|
|
|
|
|
var result = target.GetCustomAttributes(_debugColorAttributeType, false);
|
|
|
|
|
if (result.Length > 0)
|
|
|
|
|
return (TAttribute)result[0];
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2023-03-29 15:48:18 +08:00
|
|
|
|
|
|
|
|
|
private bool CheckIsHidden(Type target)
|
|
|
|
|
{
|
2023-03-29 19:58:58 +08:00
|
|
|
|
if (DebugMonitorPrefs.instance.IsShowHidden)
|
2023-03-29 15:48:18 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return target.GetCustomAttribute<DebugHideAttribute>() != null;
|
|
|
|
|
}
|
2023-03-26 11:20:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|