diff --git a/Runtime/Gizmos/DebugX.base.cs b/Runtime/Gizmos/DebugX.base.cs index f7b2a4e..6f88e85 100644 --- a/Runtime/Gizmos/DebugX.base.cs +++ b/Runtime/Gizmos/DebugX.base.cs @@ -4,6 +4,7 @@ using DCFApixels.DebugXCore.Internal; using System.Runtime.InteropServices; using Unity.Collections.LowLevel.Unsafe; using Unity.Jobs; +using UnityEditor; using UnityEngine; using UnityEngine.Rendering; @@ -277,6 +278,16 @@ namespace DCFApixels _material = material; _matrices = PinnedArray.Pin(DummyArray.Get()); _colors = PinnedArray.Pin(DummyArray.Get()); + + AssemblyReloadEvents.beforeAssemblyReload += AssemblyReloadEvents_beforeAssemblyReload; + } + private void AssemblyReloadEvents_beforeAssemblyReload() + { + AssemblyReloadEvents.beforeAssemblyReload -= AssemblyReloadEvents_beforeAssemblyReload; + _materialPropertyBlock.Clear(); + _matrices.Dispose(); + _colors.Dispose(); + _gizmos.Dispose(); } public void Prepare(GizmosList rawList) { @@ -380,7 +391,19 @@ namespace DCFApixels _materialPropertyBlock = new MaterialPropertyBlock(); _drawDatas = PinnedArray.Pin(DummyArray.Get()); _enableInstancing = IsSupportsComputeShaders && _material.GetMaterial().enableInstancing; + + AssemblyReloadEvents.beforeAssemblyReload += AssemblyReloadEvents_beforeAssemblyReload; } + private void AssemblyReloadEvents_beforeAssemblyReload() + { + AssemblyReloadEvents.beforeAssemblyReload -= AssemblyReloadEvents_beforeAssemblyReload; + _graphicsBuffer?.Release(); + _graphicsBuffer?.Dispose(); + _materialPropertyBlock.Clear(); + _drawDatas.Dispose(); + _gizmos.Dispose(); + } + public virtual int ExecuteOrder => _material.GetExecuteOrder(); public virtual bool IsStaticRender => true; protected void Prepare(GizmosList rawList) @@ -400,10 +423,7 @@ namespace DCFApixels } if (ReferenceEquals(_gizmos.Array, items) == false) { - if (_gizmos.Array != null) - { - _gizmos.Dispose(); - } + _gizmos.Dispose(); _gizmos = PinnedArray>.Pin(items); } @@ -438,9 +458,11 @@ namespace DCFApixels private readonly static int _BufferPropertyID = Shader.PropertyToID("_DataBuffer"); private void AllocateGraphicsBuffer(int capacity) { + _graphicsBuffer?.Release(); _graphicsBuffer?.Dispose(); - _materialPropertyBlock.Clear(); _graphicsBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, capacity, Marshal.SizeOf()); + + _materialPropertyBlock.Clear(); _materialPropertyBlock.SetBuffer(_BufferPropertyID, _graphicsBuffer); } } @@ -498,6 +520,17 @@ namespace DCFApixels _materialPropertyBlock = new MaterialPropertyBlock(); _drawDatas = PinnedArray.Pin(DummyArray.Get()); _enableInstancing = IsSupportsComputeShaders && _material.GetMaterial().enableInstancing; + + AssemblyReloadEvents.beforeAssemblyReload += AssemblyReloadEvents_beforeAssemblyReload; + } + private void AssemblyReloadEvents_beforeAssemblyReload() + { + AssemblyReloadEvents.beforeAssemblyReload -= AssemblyReloadEvents_beforeAssemblyReload; + _graphicsBuffer?.Release(); + _graphicsBuffer?.Dispose(); + _materialPropertyBlock.Clear(); + _drawDatas.Dispose(); + _gizmos.Dispose(); } public virtual int ExecuteOrder => _material.GetExecuteOrder() - 1; public virtual bool IsStaticRender => true; @@ -553,9 +586,11 @@ namespace DCFApixels private readonly static int _BufferPropertyID = Shader.PropertyToID("_DataBuffer"); private void AllocateGraphicsBuffer(int capacity) { + _graphicsBuffer?.Release(); _graphicsBuffer?.Dispose(); - _materialPropertyBlock.Clear(); _graphicsBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, capacity, Marshal.SizeOf()); + + _materialPropertyBlock.Clear(); _materialPropertyBlock.SetBuffer(_BufferPropertyID, _graphicsBuffer); } } diff --git a/Runtime/Gizmos/DebugX.dots.cs b/Runtime/Gizmos/DebugX.dots.cs new file mode 100644 index 0000000..f73e35e --- /dev/null +++ b/Runtime/Gizmos/DebugX.dots.cs @@ -0,0 +1,44 @@ +//#undef DEBUG +using DCFApixels.DebugXCore; +using System; +using UnityEngine; +using UnityEngine.Rendering; + +namespace DCFApixels +{ + using static DebugXConsts; + using IN = System.Runtime.CompilerServices.MethodImplAttribute; + public unsafe static partial class DebugX + { + public readonly partial struct DrawHandler + { + #region DotCross + [IN(LINE)] public DrawHandler DotCross(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(0.06f, 0.06f, 1f)); + #endregion + + #region Dot + [IN(LINE)] public DrawHandler Dot(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(DOT_SIZE, DOT_SIZE, 1f)); + #endregion + + #region WireDot + [IN(LINE)] public DrawHandler WireDot(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(DOT_SIZE * 0.5f, DOT_SIZE * 0.5f, 1f)); + #endregion + + #region DotQuad + [IN(LINE)] public DrawHandler DotQuad(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(DOT_SIZE, DOT_SIZE, 1f)); + #endregion + + #region WireDotQuad + [IN(LINE)] public DrawHandler WireDotQuad(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(DOT_SIZE, DOT_SIZE, 0f)); + #endregion + + #region DotDiamond + [IN(LINE)] public DrawHandler DotDiamond(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(DOT_SIZE * 1.16f, DOT_SIZE * 1.16f, 1f)); + #endregion + + #region WireDotDiamond + [IN(LINE)] public DrawHandler WireDotDiamond(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(DOT_SIZE * 1.16f, DOT_SIZE * 1.16f, 1f)); + #endregion + } + } +} \ No newline at end of file diff --git a/Runtime/Gizmos/DebugX.dots.cs.meta b/Runtime/Gizmos/DebugX.dots.cs.meta new file mode 100644 index 0000000..05cc195 --- /dev/null +++ b/Runtime/Gizmos/DebugX.dots.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: d5cceb4c23bcb634ca4a5fd4668ed2e1 \ No newline at end of file diff --git a/Runtime/Gizmos/DebugX.primitives.cs b/Runtime/Gizmos/DebugX.primitives.cs index ae03eb9..891a912 100644 --- a/Runtime/Gizmos/DebugX.primitives.cs +++ b/Runtime/Gizmos/DebugX.primitives.cs @@ -20,10 +20,6 @@ namespace DCFApixels [IN(LINE)] public DrawHandler Cross(Vector3 position, float size) => Mesh(position, Quaternion.identity, new Vector3(size, size, size)); #endregion - #region DotCross - [IN(LINE)] public DrawHandler DotCross(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(0.06f, 0.06f, 1f)); - #endregion - #region Sphere [IN(LINE)] public DrawHandler Sphere(Vector3 position, float radius) => Mesh(position, Quaternion.identity, new Vector3(radius, radius, radius)); @@ -122,14 +118,6 @@ namespace DCFApixels [IN(LINE)] public DrawHandler WireCircle(Vector3 position, Quaternion rotation, float radius) => Mesh(position, rotation, new Vector3(radius, radius, radius)); #endregion - #region Dot - [IN(LINE)] public DrawHandler Dot(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(DOT_SIZE, DOT_SIZE, 1f)); - #endregion - - #region WireDot - [IN(LINE)] public DrawHandler WireDot(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(DOT_SIZE * 0.5f, DOT_SIZE * 0.5f, 1f)); - #endregion - #region Cylinder [IN(LINE)] @@ -246,6 +234,7 @@ namespace DCFApixels } #endregion + #region Capsule [IN(LINE)] public DrawHandler Capsule(Vector3 position, Quaternion rotation, float radius, float height) @@ -539,22 +528,6 @@ namespace DCFApixels return this; } #endregion - - #region DotQuad - [IN(LINE)] public DrawHandler DotQuad(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(DOT_SIZE, DOT_SIZE, 1f)); - #endregion - - #region WireDotQuad - [IN(LINE)] public DrawHandler WireDotQuad(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(DOT_SIZE, DOT_SIZE, 0f)); - #endregion - - #region DotDiamond - [IN(LINE)] public DrawHandler DotDiamond(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(DOT_SIZE * 1.16f, DOT_SIZE * 1.16f, 1f)); - #endregion - - #region WireDotDiamond - [IN(LINE)] public DrawHandler WireDotDiamond(Vector3 position) => Mesh(position, Quaternion.identity, new Vector3(DOT_SIZE * 1.16f, DOT_SIZE * 1.16f, 1f)); - #endregion } } } \ No newline at end of file