This commit is contained in:
DCFApixels 2025-02-28 17:06:43 +08:00
parent bc8f2cedf1
commit c2794bf715
4 changed files with 52 additions and 6 deletions

View File

@ -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<DebugXDrawGizmoAttribute>().Select(o => (o, o.GetCustomAttribute<DebugXDrawGizmoAttribute>())).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();

View File

@ -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;
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 884ed13700ff7c44e86f92c859f02dc5

View File

@ -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;