mirror of
https://github.com/DCFApixels/Unity-DebugX.git
synced 2025-09-18 18:14:36 +08:00
polishing
This commit is contained in:
parent
1d97c637ff
commit
8743b77dfa
@ -22,8 +22,14 @@ namespace DCFApixels
|
|||||||
private readonly static bool IsSupportsComputeShaders = SystemInfo.supportsComputeShaders;
|
private readonly static bool IsSupportsComputeShaders = SystemInfo.supportsComputeShaders;
|
||||||
|
|
||||||
public const float IMMEDIATE_DURATION = -1;
|
public const float IMMEDIATE_DURATION = -1;
|
||||||
}
|
|
||||||
|
|
||||||
|
private enum PauseStateX
|
||||||
|
{
|
||||||
|
Unpaused = 0,
|
||||||
|
PreUnpaused = 1, //нужно чтобы отщелкунть паузу с задержкой в один тик
|
||||||
|
Paused = 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
public enum DebugXLine
|
public enum DebugXLine
|
||||||
{
|
{
|
||||||
Default,
|
Default,
|
||||||
|
@ -12,7 +12,6 @@ using UnityEngine.LowLevel;
|
|||||||
using UnityEngine.PlayerLoop;
|
using UnityEngine.PlayerLoop;
|
||||||
using Unity.Collections.LowLevel.Unsafe;
|
using Unity.Collections.LowLevel.Unsafe;
|
||||||
using DCFApixels.DebugXCore.Internal;
|
using DCFApixels.DebugXCore.Internal;
|
||||||
using static DCFApixels.DebugXCore.DebugXUtility;
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
#endif
|
#endif
|
||||||
@ -47,12 +46,6 @@ namespace DCFApixels
|
|||||||
{
|
{
|
||||||
_isCameraContext = false;
|
_isCameraContext = false;
|
||||||
}
|
}
|
||||||
private enum PauseStateX
|
|
||||||
{
|
|
||||||
Unpaused = 0,
|
|
||||||
PreUnpaused = 1, //íóæíî ÷òîáû îòùåëêóíòü ïàóçó ñ çàäåðæêîé â îäèí òèê
|
|
||||||
Paused = 2,
|
|
||||||
}
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
private static void EditorApplication_pauseStateChanged(PauseState obj)
|
private static void EditorApplication_pauseStateChanged(PauseState obj)
|
||||||
{
|
{
|
||||||
@ -66,8 +59,8 @@ namespace DCFApixels
|
|||||||
{
|
{
|
||||||
InitGlobals();
|
InitGlobals();
|
||||||
|
|
||||||
Meshes = StaticDataLoader.Load(new MeshesList(), $"DCFApixels.DebugX/MeshesList");
|
Meshes = DebugXUtility.LoadStaticData(new MeshesList(), $"DCFApixels.DebugX/MeshesList");
|
||||||
Materials = StaticDataLoader.Load(new MaterialsList(), $"DCFApixels.DebugX/MaterialsList");
|
Materials = DebugXUtility.LoadStaticData(new MaterialsList(), $"DCFApixels.DebugX/MaterialsList");
|
||||||
|
|
||||||
IsSRP = GraphicsSettings.currentRenderPipeline != null;
|
IsSRP = GraphicsSettings.currentRenderPipeline != null;
|
||||||
|
|
||||||
@ -308,7 +301,7 @@ namespace DCFApixels
|
|||||||
_lastEditorTicks = _editorTicks;
|
_lastEditorTicks = _editorTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsGizmosRender())
|
if (DebugXUtility.IsGizmosRender())
|
||||||
{
|
{
|
||||||
RenderContextController.StaicContextController.Prepare();
|
RenderContextController.StaicContextController.Prepare();
|
||||||
RenderContextController.StaicContextController.Render(cbExecutor);
|
RenderContextController.StaicContextController.Render(cbExecutor);
|
||||||
@ -512,7 +505,7 @@ namespace DCFApixels
|
|||||||
}
|
}
|
||||||
private void TypeCode_OnAddNewID(int count)
|
private void TypeCode_OnAddNewID(int count)
|
||||||
{
|
{
|
||||||
Array.Resize(ref _buffersMap, NextPow2(count));
|
Array.Resize(ref _buffersMap, DebugXUtility.NextPow2(count));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -642,6 +635,7 @@ namespace DCFApixels
|
|||||||
public void Prepare(Camera camera, GizmosList<T> list) { }
|
public void Prepare(Camera camera, GizmosList<T> list) { }
|
||||||
public void Render(Camera camera, GizmosList<T> list, CommandBuffer cb) { }
|
public void Render(Camera camera, GizmosList<T> list, CommandBuffer cb) { }
|
||||||
}
|
}
|
||||||
|
private static readonly bool _isUnmanaged = UnsafeUtility.IsUnmanaged(typeof(T));
|
||||||
|
|
||||||
private StructList<GizmoInternal<T>> _gizmos = new StructList<GizmoInternal<T>>(32);
|
private StructList<GizmoInternal<T>> _gizmos = new StructList<GizmoInternal<T>>(32);
|
||||||
private readonly string _debugName;
|
private readonly string _debugName;
|
||||||
@ -655,17 +649,20 @@ namespace DCFApixels
|
|||||||
private readonly bool _isStatic;
|
private readonly bool _isStatic;
|
||||||
|
|
||||||
#if DEV_MODE
|
#if DEV_MODE
|
||||||
private static readonly Unity.Profiling.ProfilerMarker _timerMarker = new Unity.Profiling.ProfilerMarker($"{GetGenericTypeName_Internal(typeof(T), 3, false)}.{nameof(UpdateTimer)}");
|
private static readonly Unity.Profiling.ProfilerMarker _timerMarker = new Unity.Profiling.ProfilerMarker($"{DebugXUtility.GetGenericTypeName(typeof(T), 3, false)}.{nameof(UpdateTimer)}");
|
||||||
private static readonly Unity.Profiling.ProfilerMarker _prepareMarker = new Unity.Profiling.ProfilerMarker($"{GetGenericTypeName_Internal(typeof(T), 3, false)}.{nameof(Prepare)}");
|
private static readonly Unity.Profiling.ProfilerMarker _prepareMarker = new Unity.Profiling.ProfilerMarker($"{DebugXUtility.GetGenericTypeName(typeof(T), 3, false)}.{nameof(Prepare)}");
|
||||||
private static readonly Unity.Profiling.ProfilerMarker _renderMarker = new Unity.Profiling.ProfilerMarker($"{GetGenericTypeName_Internal(typeof(T), 3, false)}.{nameof(Render)}");
|
private static readonly Unity.Profiling.ProfilerMarker _renderMarker = new Unity.Profiling.ProfilerMarker($"{DebugXUtility.GetGenericTypeName(typeof(T), 3, false)}.{nameof(Render)}");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
public override int ExecuteOrder { get { return _renderer.ExecuteOrder; } }
|
||||||
|
|
||||||
|
|
||||||
public GizmosBuffer(RenderContext context, CommandBuffer cb)
|
public GizmosBuffer(RenderContext context, CommandBuffer cb)
|
||||||
{
|
{
|
||||||
Type type = typeof(T);
|
Type type = typeof(T);
|
||||||
_context = context;
|
_context = context;
|
||||||
_staticCommandBuffer = cb;
|
_staticCommandBuffer = cb;
|
||||||
_debugName = GetGenericTypeName_Internal(type, 3, false);
|
_debugName = DebugXUtility.GetGenericTypeName(type, 3, false);
|
||||||
//_dynamicCommandBuffer = new CommandBuffer();
|
//_dynamicCommandBuffer = new CommandBuffer();
|
||||||
//_dynamicCommandBuffer.name = _debugName;
|
//_dynamicCommandBuffer.name = _debugName;
|
||||||
|
|
||||||
@ -696,10 +693,6 @@ namespace DCFApixels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int ExecuteOrder { get { return _renderer.ExecuteOrder; } }
|
|
||||||
|
|
||||||
|
|
||||||
private static readonly bool _isUnmanaged = UnsafeUtility.IsUnmanaged(typeof(T));
|
|
||||||
public sealed override int UpdateTimer(float deltaTime)
|
public sealed override int UpdateTimer(float deltaTime)
|
||||||
{
|
{
|
||||||
_staticCommandBuffer.Clear();
|
_staticCommandBuffer.Clear();
|
||||||
|
2
Runtime/DebugX.globals.cs.meta
Normal file
2
Runtime/DebugX.globals.cs.meta
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b42093f02e7c98c4395413fe24c0784b
|
@ -4,9 +4,7 @@ using Unity.Collections.LowLevel.Unsafe;
|
|||||||
using Unity.Jobs;
|
using Unity.Jobs;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Rendering;
|
using UnityEngine.Rendering;
|
||||||
using static DCFApixels.DebugXCore.DebugXUtility;
|
|
||||||
using DCFApixels.DebugXCore.Internal;
|
using DCFApixels.DebugXCore.Internal;
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
#endif
|
#endif
|
||||||
@ -346,8 +344,8 @@ namespace DCFApixels
|
|||||||
_matrices.Dispose();
|
_matrices.Dispose();
|
||||||
_colors.Dispose();
|
_colors.Dispose();
|
||||||
}
|
}
|
||||||
_matrices = PinnedArray<Matrix4x4>.Pin(new Matrix4x4[NextPow2(count)]);
|
_matrices = PinnedArray<Matrix4x4>.Pin(new Matrix4x4[DebugXUtility.NextPow2(count)]);
|
||||||
_colors = PinnedArray<Color>.Pin(new Color[NextPow2(count)]).As<Vector4>();
|
_colors = PinnedArray<Color>.Pin(new Color[DebugXUtility.NextPow2(count)]).As<Vector4>();
|
||||||
_buffersLength = count;
|
_buffersLength = count;
|
||||||
}
|
}
|
||||||
if (ReferenceEquals(_gizmos.Array, items) == false)
|
if (ReferenceEquals(_gizmos.Array, items) == false)
|
||||||
@ -446,8 +444,8 @@ namespace DCFApixels
|
|||||||
{
|
{
|
||||||
_matrices.Dispose();
|
_matrices.Dispose();
|
||||||
_colors.Dispose();
|
_colors.Dispose();
|
||||||
_matrices = PinnedArray<Matrix4x4>.Pin(new Matrix4x4[NextPow2(count)]);
|
_matrices = PinnedArray<Matrix4x4>.Pin(new Matrix4x4[DebugXUtility.NextPow2(count)]);
|
||||||
_colors = PinnedArray<Vector4>.Pin(new Vector4[NextPow2(count)]);
|
_colors = PinnedArray<Vector4>.Pin(new Vector4[DebugXUtility.NextPow2(count)]);
|
||||||
_buffersLength = count;
|
_buffersLength = count;
|
||||||
}
|
}
|
||||||
if (ReferenceEquals(_gizmos.Array, items) == false)
|
if (ReferenceEquals(_gizmos.Array, items) == false)
|
||||||
@ -554,8 +552,8 @@ namespace DCFApixels
|
|||||||
_matrices.Dispose();
|
_matrices.Dispose();
|
||||||
_colors.Dispose();
|
_colors.Dispose();
|
||||||
}
|
}
|
||||||
_matrices = PinnedArray<Matrix4x4>.Pin(new Matrix4x4[NextPow2(count)]);
|
_matrices = PinnedArray<Matrix4x4>.Pin(new Matrix4x4[DebugXUtility.NextPow2(count)]);
|
||||||
_colors = PinnedArray<Vector4>.Pin(new Vector4[NextPow2(count)]);
|
_colors = PinnedArray<Vector4>.Pin(new Vector4[DebugXUtility.NextPow2(count)]);
|
||||||
_buffersLength = count;
|
_buffersLength = count;
|
||||||
}
|
}
|
||||||
if (ReferenceEquals(_gizmos.Array, items) == false)
|
if (ReferenceEquals(_gizmos.Array, items) == false)
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
using DCFApixels.DebugXCore;
|
using DCFApixels.DebugXCore;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Rendering;
|
using UnityEngine.Rendering;
|
||||||
using static DCFApixels.DebugXCore.DebugXUtility;
|
|
||||||
|
|
||||||
namespace DCFApixels
|
namespace DCFApixels
|
||||||
{
|
{
|
||||||
@ -40,7 +39,7 @@ namespace DCFApixels
|
|||||||
const float MinDistance = 2.5f;
|
const float MinDistance = 2.5f;
|
||||||
Vector3 direction = end - start;
|
Vector3 direction = end - start;
|
||||||
|
|
||||||
float distance = FastSqrt(direction.sqrMagnitude);
|
float distance = DebugXUtility.FastSqrt(direction.sqrMagnitude);
|
||||||
Quaternion rotation = direction == default ? Quaternion.identity : Quaternion.LookRotation(direction);
|
Quaternion rotation = direction == default ? Quaternion.identity : Quaternion.LookRotation(direction);
|
||||||
|
|
||||||
var arrowSize = 0.5f;
|
var arrowSize = 0.5f;
|
||||||
|
@ -3,7 +3,6 @@ using DCFApixels.DebugXCore;
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Rendering;
|
using UnityEngine.Rendering;
|
||||||
using static DCFApixels.DebugXCore.DebugXUtility;
|
|
||||||
|
|
||||||
namespace DCFApixels
|
namespace DCFApixels
|
||||||
{
|
{
|
||||||
@ -88,7 +87,7 @@ namespace DCFApixels
|
|||||||
float x = sqrRadius * sqrRadius / sqrMagnitude;
|
float x = sqrRadius * sqrRadius / sqrMagnitude;
|
||||||
if (x / sqrRadius < 1f)
|
if (x / sqrRadius < 1f)
|
||||||
{
|
{
|
||||||
float resultSize = FastSqrt(sqrRadius - x);
|
float resultSize = DebugXUtility.FastSqrt(sqrRadius - x);
|
||||||
|
|
||||||
_buffer[i] = new Gizmo<InstancingMeshGizmoLayout>(
|
_buffer[i] = new Gizmo<InstancingMeshGizmoLayout>(
|
||||||
new InstancingMeshGizmoLayout(
|
new InstancingMeshGizmoLayout(
|
||||||
|
@ -67,7 +67,7 @@ Shader "DCFApixels/DebugX/Handles Wire"
|
|||||||
o.color = input[i].color;
|
o.color = input[i].color;
|
||||||
lineStream.Append(o);
|
lineStream.Append(o);
|
||||||
|
|
||||||
int next = (i + 1) % 3;
|
uint next = (i + 1) % 3;
|
||||||
o.vertex = input[next].vertex;
|
o.vertex = input[next].vertex;
|
||||||
o.color = input[next].color;
|
o.color = input[next].color;
|
||||||
lineStream.Append(o);
|
lineStream.Append(o);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using static DCFApixels.DebugX;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
#endif
|
#endif
|
||||||
@ -10,7 +12,56 @@ namespace DCFApixels.DebugXCore
|
|||||||
using IN = System.Runtime.CompilerServices.MethodImplAttribute;
|
using IN = System.Runtime.CompilerServices.MethodImplAttribute;
|
||||||
public static class DebugXUtility
|
public static class DebugXUtility
|
||||||
{
|
{
|
||||||
public static string GetGenericTypeName_Internal(Type type, int maxDepth, bool isFull)
|
private const MethodImplOptions LINE = MethodImplOptions.AggressiveInlining;
|
||||||
|
public static T LoadStaticData<T>(T instance, string path)
|
||||||
|
{
|
||||||
|
object obj = instance;
|
||||||
|
var type = obj.GetType();
|
||||||
|
var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||||
|
var prefab = Resources.Load<GameObject>(path);
|
||||||
|
|
||||||
|
if (prefab == null)
|
||||||
|
{
|
||||||
|
Debug.LogError($"{path} not found.");
|
||||||
|
return (T)obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fields.Count() <= 0)
|
||||||
|
{
|
||||||
|
Debug.LogError($"{typeof(T).Name} no fields.");
|
||||||
|
return (T)obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var field in fields.Where(o => o.FieldType == typeof(Mesh)))
|
||||||
|
{
|
||||||
|
var child = prefab.transform.Find(field.Name);
|
||||||
|
var meshFilter = child.GetComponent<MeshFilter>();
|
||||||
|
if (meshFilter != null)
|
||||||
|
{
|
||||||
|
field.SetValue(obj, meshFilter.sharedMesh);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogWarning(field.Name + " not found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var field in fields.Where(o => o.FieldType == typeof(Material)))
|
||||||
|
{
|
||||||
|
var child = prefab.transform.Find(field.Name);
|
||||||
|
var meshFilter = child.GetComponent<Renderer>();
|
||||||
|
if (meshFilter != null)
|
||||||
|
{
|
||||||
|
field.SetValue(obj, meshFilter.sharedMaterial);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogWarning(field.Name + " not found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (T)obj;
|
||||||
|
}
|
||||||
|
public static string GetGenericTypeName(Type type, int maxDepth, bool isFull)
|
||||||
{
|
{
|
||||||
#if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
|
#if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает
|
||||||
string typeName = isFull ? type.FullName : type.Name;
|
string typeName = isFull ? type.FullName : type.Name;
|
||||||
@ -29,7 +80,7 @@ namespace DCFApixels.DebugXCore
|
|||||||
for (int i = 0; i < typeParameters.Length; ++i)
|
for (int i = 0; i < typeParameters.Length; ++i)
|
||||||
{
|
{
|
||||||
//чтобы строка не была слишком длинной, используются сокращенные имена для типов аргументов
|
//чтобы строка не была слишком длинной, используются сокращенные имена для типов аргументов
|
||||||
string paramTypeName = GetGenericTypeName_Internal(typeParameters[i], maxDepth - 1, false);
|
string paramTypeName = GetGenericTypeName(typeParameters[i], maxDepth - 1, false);
|
||||||
genericParams += (i == 0 ? paramTypeName : $", {paramTypeName}");
|
genericParams += (i == 0 ? paramTypeName : $", {paramTypeName}");
|
||||||
}
|
}
|
||||||
return $"{typeName}<{genericParams}>";
|
return $"{typeName}<{genericParams}>";
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace DCFApixels.DebugXCore
|
|
||||||
{
|
|
||||||
public static class StaticDataLoader
|
|
||||||
{
|
|
||||||
public static T Load<T>(T instance, string path)
|
|
||||||
{
|
|
||||||
object obj = instance;
|
|
||||||
var type = obj.GetType();
|
|
||||||
var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
|
||||||
var prefab = Resources.Load<GameObject>(path);
|
|
||||||
|
|
||||||
if (prefab == null)
|
|
||||||
{
|
|
||||||
Debug.LogError($"{path} not found");
|
|
||||||
return (T)obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fields.Count() <= 0)
|
|
||||||
{
|
|
||||||
Debug.LogError($"{typeof(T).Name} no fields");
|
|
||||||
return (T)obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var field in fields.Where(o => o.FieldType == typeof(Mesh)))
|
|
||||||
{
|
|
||||||
var child = prefab.transform.Find(field.Name);
|
|
||||||
var meshFilter = child.GetComponent<MeshFilter>();
|
|
||||||
if (meshFilter != null)
|
|
||||||
{
|
|
||||||
field.SetValue(obj, meshFilter.sharedMesh);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogWarning(field.Name + " not found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (var field in fields.Where(o => o.FieldType == typeof(Material)))
|
|
||||||
{
|
|
||||||
var child = prefab.transform.Find(field.Name);
|
|
||||||
var meshFilter = child.GetComponent<Renderer>();
|
|
||||||
if (meshFilter != null)
|
|
||||||
{
|
|
||||||
field.SetValue(obj, meshFilter.sharedMaterial);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.LogWarning(field.Name + " not found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (T)obj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,2 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 2482dd3495375b040ab937f0af691464
|
|
16
Samples/DebugX.Samples.asmdef
Normal file
16
Samples/DebugX.Samples.asmdef
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "DCFApixels.DebugX.Samples",
|
||||||
|
"rootNamespace": "DCFApixels",
|
||||||
|
"references": [
|
||||||
|
"GUID:1139531e2a3a6bd4c8ad2bc68ae00719"
|
||||||
|
],
|
||||||
|
"includePlatforms": [],
|
||||||
|
"excludePlatforms": [],
|
||||||
|
"allowUnsafeCode": true,
|
||||||
|
"overrideReferences": false,
|
||||||
|
"precompiledReferences": [],
|
||||||
|
"autoReferenced": true,
|
||||||
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
|
}
|
7
Samples/DebugX.Samples.asmdef.meta
Normal file
7
Samples/DebugX.Samples.asmdef.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ad77f906ceb59f143976326b11159337
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user