From c2794bf715aaa7a1335b280faa43accd70d3e135 Mon Sep 17 00:00:00 2001 From: DCFApixels <99481254+DCFApixels@users.noreply.github.com> Date: Fri, 28 Feb 2025 17:06:43 +0800 Subject: [PATCH] stash --- Runtime/DebugX.cs | 28 +++++++++++++++++-- Runtime/Utils/DebugXDrawGizmoAttribute.cs | 14 ++++++++++ .../Utils/DebugXDrawGizmoAttribute.cs.meta | 2 ++ Samples/Scripts/DebugXSample_Lines.cs | 14 +++++++--- 4 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 Runtime/Utils/DebugXDrawGizmoAttribute.cs create mode 100644 Runtime/Utils/DebugXDrawGizmoAttribute.cs.meta diff --git a/Runtime/DebugX.cs b/Runtime/DebugX.cs index 8796bbb..f1e3ef5 100644 --- a/Runtime/DebugX.cs +++ b/Runtime/DebugX.cs @@ -14,12 +14,13 @@ using Unity.Collections.LowLevel.Unsafe; using DCFApixels.DebugXCore.Internal; #if UNITY_EDITOR using UnityEditor; +using System.Reflection; +using System.Linq; #endif namespace DCFApixels { using static DebugXConsts; - using static UnityEngine.PlayerLoop.PostLateUpdate; using IN = System.Runtime.CompilerServices.MethodImplAttribute; public static unsafe partial class DebugX { @@ -34,6 +35,10 @@ namespace DCFApixels private static ulong _renderTicks = 100; private static ulong _timeTicks = 0; +#if UNITY_EDITOR + private static (MethodInfo method, DebugXDrawGizmoAttribute attribute)[] _drawGizmosMethods; +#endif + public static ulong RenderTicks { get { return _renderTicks; } @@ -70,7 +75,6 @@ namespace DCFApixels { InitGlobals(); - if (IsSRP) { RenderPipelineManager.beginCameraRendering -= OnPreRender_SRP; @@ -115,7 +119,9 @@ namespace DCFApixels //Application.onBeforeRender -= Application_onBeforeRender; //Application.onBeforeRender += Application_onBeforeRender; + #if UNITY_EDITOR + _drawGizmosMethods = TypeCache.GetMethodsWithAttribute().Select(o => (o, o.GetCustomAttribute())).ToArray(); EditorApplication.pauseStateChanged -= EditorApplication_pauseStateChanged; EditorApplication.pauseStateChanged += EditorApplication_pauseStateChanged; EditorApplication.update -= EditorApplication_update; @@ -302,6 +308,24 @@ namespace DCFApixels if (DebugXUtility.IsGizmosRender()) { + if(_drawGizmosMethods.Length > 0) + { + object[] oneObjParams = new object[1]; + for (int i = 0; i < _drawGizmosMethods.Length; i++) + { + var pair = _drawGizmosMethods[i]; + var objects = UnityEngine.Object.FindObjectsByType(pair.attribute.Type, FindObjectsInactive.Exclude, FindObjectsSortMode.None); + for (int j = 0; j < objects.Length; j++) + { + oneObjParams[0] = objects[j]; + pair.method.Invoke(null, oneObjParams); + } + } + } + + + + RenderContextController.StaicContextController.Prepare(); RenderContextController.StaicContextController.Render(cbExecutor); cbExecutor.Submit(); diff --git a/Runtime/Utils/DebugXDrawGizmoAttribute.cs b/Runtime/Utils/DebugXDrawGizmoAttribute.cs new file mode 100644 index 0000000..02278b1 --- /dev/null +++ b/Runtime/Utils/DebugXDrawGizmoAttribute.cs @@ -0,0 +1,14 @@ +using System; + +namespace DCFApixels.DebugXCore +{ + [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] + public sealed class DebugXDrawGizmoAttribute : Attribute + { + public Type Type; + public DebugXDrawGizmoAttribute(Type type) + { + Type = type; + } + } +} \ No newline at end of file diff --git a/Runtime/Utils/DebugXDrawGizmoAttribute.cs.meta b/Runtime/Utils/DebugXDrawGizmoAttribute.cs.meta new file mode 100644 index 0000000..6642528 --- /dev/null +++ b/Runtime/Utils/DebugXDrawGizmoAttribute.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 884ed13700ff7c44e86f92c859f02dc5 \ No newline at end of file diff --git a/Samples/Scripts/DebugXSample_Lines.cs b/Samples/Scripts/DebugXSample_Lines.cs index 1c8d512..0b80a54 100644 --- a/Samples/Scripts/DebugXSample_Lines.cs +++ b/Samples/Scripts/DebugXSample_Lines.cs @@ -13,16 +13,22 @@ namespace DCFApixels.DebugXCore.Samples public float WidthMultiplier = 1f; #if UNITY_EDITOR - private void OnDrawGizmos() - { - Draw(); - } + //private void OnDrawGizmos() + //{ + // Draw(); + //} #else private void Update() { Draw(); } #endif + [DebugXDrawGizmo(typeof(DebugXSample_Lines))] + private static void DrawGizmos(DebugXSample_Lines obj) + { + obj.Draw(); + } + private void Draw() { int i = -1;