From 339369bc7391761ec20d3fae02f7d080e5572c22 Mon Sep 17 00:00:00 2001 From: DCFApixels <99481254+DCFApixels@users.noreply.github.com> Date: Mon, 24 Feb 2025 10:59:58 +0800 Subject: [PATCH] update --- Runtime/DebugX.cs | 5 +- Runtime/Gizmos/DebugX.base.cs | 1 + Runtime/Gizmos/DebugX.lines.cs | 1 + Runtime/Gizmos/DebugX.primitives.cs | 1 + Runtime/Gizmos/DebugX.raycasts.cs | 14 +-- Runtime/Utils/DebugX.assets.cs | 1 - Runtime/Utils/DebugX.utils.cs | 99 +------------------ Runtime/Utils/DebugXUtility.cs | 85 ++++++++++++++++ Runtime/Utils/DebugXUtility.cs.meta | 2 + .../{Internal => Utils}/StaticDataLoader.cs | 0 .../StaticDataLoader.cs.meta | 0 Samples/Other/FakeLightMat.mat | 2 +- Samples/Scripts/DebugXSample_Lines.cs | 2 +- Samples/Scripts/DebugXSample_Other.cs | 3 +- Samples/Scripts/DebugXSample_Primitives2D.cs | 2 +- Samples/Scripts/DebugXSample_Primitives3D.cs | 2 +- Samples/Scripts/DebugXSample_Raycasts2D.cs | 2 +- Samples/Scripts/DebugXSample_Raycasts3D.cs | 2 +- 18 files changed, 110 insertions(+), 114 deletions(-) create mode 100644 Runtime/Utils/DebugXUtility.cs create mode 100644 Runtime/Utils/DebugXUtility.cs.meta rename Runtime/{Internal => Utils}/StaticDataLoader.cs (100%) rename Runtime/{Internal => Utils}/StaticDataLoader.cs.meta (100%) diff --git a/Runtime/DebugX.cs b/Runtime/DebugX.cs index ff612c2..de0c2a3 100644 --- a/Runtime/DebugX.cs +++ b/Runtime/DebugX.cs @@ -12,6 +12,7 @@ using UnityEngine.LowLevel; using UnityEngine.PlayerLoop; using Unity.Collections.LowLevel.Unsafe; using DCFApixels.DebugXCore.Internal; +using static DCFApixels.DebugXCore.DebugXUtility; #if UNITY_EDITOR using UnityEditor; #endif @@ -200,7 +201,7 @@ namespace DCFApixels #region Draw/DrawHandler private static float GetCurrentDefaultDuration() { - if(GetCurrentContextController().Context.Camera == null) + if (GetCurrentContextController().Context.Camera == null) { return DEFAULT_DURATION; } @@ -407,7 +408,7 @@ namespace DCFApixels } public void Execute(CommandBuffer cb) { - if(RenderContext == default) + if (RenderContext == default) { Graphics.ExecuteCommandBuffer(cb); } diff --git a/Runtime/Gizmos/DebugX.base.cs b/Runtime/Gizmos/DebugX.base.cs index fc641f8..4dcb1fb 100644 --- a/Runtime/Gizmos/DebugX.base.cs +++ b/Runtime/Gizmos/DebugX.base.cs @@ -4,6 +4,7 @@ using Unity.Collections.LowLevel.Unsafe; using Unity.Jobs; using UnityEngine; using UnityEngine.Rendering; +using static DCFApixels.DebugXCore.DebugXUtility; #if UNITY_EDITOR using UnityEditor; #endif diff --git a/Runtime/Gizmos/DebugX.lines.cs b/Runtime/Gizmos/DebugX.lines.cs index cec8811..493233d 100644 --- a/Runtime/Gizmos/DebugX.lines.cs +++ b/Runtime/Gizmos/DebugX.lines.cs @@ -2,6 +2,7 @@ using DCFApixels.DebugXCore; using UnityEngine; using UnityEngine.Rendering; +using static DCFApixels.DebugXCore.DebugXUtility; namespace DCFApixels { diff --git a/Runtime/Gizmos/DebugX.primitives.cs b/Runtime/Gizmos/DebugX.primitives.cs index 56a327a..4e0ee98 100644 --- a/Runtime/Gizmos/DebugX.primitives.cs +++ b/Runtime/Gizmos/DebugX.primitives.cs @@ -3,6 +3,7 @@ using DCFApixels.DebugXCore; using System; using UnityEngine; using UnityEngine.Rendering; +using static DCFApixels.DebugXCore.DebugXUtility; namespace DCFApixels { diff --git a/Runtime/Gizmos/DebugX.raycasts.cs b/Runtime/Gizmos/DebugX.raycasts.cs index d9f63e4..59c2724 100644 --- a/Runtime/Gizmos/DebugX.raycasts.cs +++ b/Runtime/Gizmos/DebugX.raycasts.cs @@ -168,7 +168,7 @@ namespace DCFApixels RayArrow(new Vector3(hit.point.x, hit.point.y, origin.z), hit.normal); //Setup(Color.SetAlpha(ShadowAlphaMultiplier)). - Line(origin, end); + Line(origin, end); } return this; } @@ -198,7 +198,7 @@ namespace DCFApixels //Setup(Color.SetAlpha(ShadowAlphaMultiplier)). - Line(origin, end); + Line(origin, end); } return this; } @@ -220,16 +220,16 @@ namespace DCFApixels else { Vector3 end = origin + (Vector3)direction * hit.distance; - + //WidthOutLine(origin, end, radius * 2f); - + DotDiamond(new Vector3(hit.point.x, hit.point.y, origin.z)); WireFlatCapsule(end, rotation, radius, height); RayArrow(new Vector3(hit.point.x, hit.point.y, origin.z), hit.normal); - - + + //Setup(Color.SetAlpha(ShadowAlphaMultiplier)). - Line(origin, end); + Line(origin, end); } return this; } diff --git a/Runtime/Utils/DebugX.assets.cs b/Runtime/Utils/DebugX.assets.cs index 09fc70b..5fdac1c 100644 --- a/Runtime/Utils/DebugX.assets.cs +++ b/Runtime/Utils/DebugX.assets.cs @@ -1,5 +1,4 @@ using UnityEngine; -using UnityEngine.Rendering; namespace DCFApixels { diff --git a/Runtime/Utils/DebugX.utils.cs b/Runtime/Utils/DebugX.utils.cs index c468889..03e9ca0 100644 --- a/Runtime/Utils/DebugX.utils.cs +++ b/Runtime/Utils/DebugX.utils.cs @@ -3,15 +3,12 @@ #if DEBUG #define DEV_MODE #endif -using UnityEngine; +using System; +using System.Buffers; using System.Collections.Generic; using System.Linq; -using System; using Unity.Collections.LowLevel.Unsafe; -using System.Buffers; -#if UNITY_EDITOR -using UnityEditor; -#endif + namespace DCFApixels { @@ -19,96 +16,6 @@ namespace DCFApixels public static unsafe partial class DebugX { - #region Utils Methods - private static string GetGenericTypeName_Internal(Type type, int maxDepth, bool isFull) - { -#if (DEBUG && !DISABLE_DEBUG) || !REFLECTION_DISABLED // REFLECTION_DISABLED - string typeName = isFull ? type.FullName : type.Name; - if (!type.IsGenericType || maxDepth == 0) - { - return typeName; - } - int genericInfoIndex = typeName.LastIndexOf('`'); - if (genericInfoIndex > 0) - { - typeName = typeName.Remove(genericInfoIndex); - } - - string genericParams = ""; - Type[] typeParameters = type.GetGenericArguments(); - for (int i = 0; i < typeParameters.Length; ++i) - { - // , - string paramTypeName = GetGenericTypeName_Internal(typeParameters[i], maxDepth - 1, false); - genericParams += (i == 0 ? paramTypeName : $", {paramTypeName}"); - } - return $"{typeName}<{genericParams}>"; -#else - Debug.LogWarning($"Reflection is not available, the {nameof(GetGenericTypeName_Internal)} method does not work."); - return isFull ? type.FullName : type.Name; -#endif - } - - [IN(LINE)] - public static float FastMagnitude(Vector3 v) - { - return FastSqrt(v.x * v.x + v.y * v.y + v.z * v.z); - } - [IN(LINE)] - private static unsafe float FastSqrt(float number) - { - long i; - float x2, y; - const float threehalfs = 1.5F; - - x2 = number * 0.5F; - y = number; - i = *(long*)&y; // evil floating point bit level hacking - i = 0x5f3759df - (i >> 1); // what the fuck? - y = *(float*)&i; - y = y * (threehalfs - (x2 * y * y)); // 1st iteration - //y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed - - return 1 / y; - } - [IN(LINE)] - private static int NextPow2(int v) - { - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - return ++v; - } - private static Color[] _setColorBuffer = new Color[64]; - [IN(LINE)] - static void AddColorsToMesh(Mesh mesh, Color color) - { - int vertexCount = mesh.vertexCount; - if (_setColorBuffer.Length < vertexCount) - { - _setColorBuffer = new Color[NextPow2(vertexCount)]; - } - for (int i = 0; i < mesh.vertexCount; i++) - { - _setColorBuffer[i] = color; - } - mesh.SetColors(_setColorBuffer, 0, vertexCount); - } - - [IN(LINE)] - private static bool IsGizmosRender() - { - bool result = true; -#if UNITY_EDITOR - result = Handles.ShouldRenderGizmos(); -#endif - return result; - } - #endregion - #region private StructList private interface IStructListElement { diff --git a/Runtime/Utils/DebugXUtility.cs b/Runtime/Utils/DebugXUtility.cs new file mode 100644 index 0000000..6b9242b --- /dev/null +++ b/Runtime/Utils/DebugXUtility.cs @@ -0,0 +1,85 @@ +using System; +using UnityEngine; +using static DCFApixels.DebugX; +#if UNITY_EDITOR +using UnityEditor; +#endif + +namespace DCFApixels.DebugXCore +{ + using IN = System.Runtime.CompilerServices.MethodImplAttribute; + public static class DebugXUtility + { + public static string GetGenericTypeName_Internal(Type type, int maxDepth, bool isFull) + { +#if DEBUG || !REFLECTION_DISABLED //в дебажных утилитах REFLECTION_DISABLED только в релизном билде работает + string typeName = isFull ? type.FullName : type.Name; + if (!type.IsGenericType || maxDepth == 0) + { + return typeName; + } + int genericInfoIndex = typeName.LastIndexOf('`'); + if (genericInfoIndex > 0) + { + typeName = typeName.Remove(genericInfoIndex); + } + + string genericParams = ""; + Type[] typeParameters = type.GetGenericArguments(); + for (int i = 0; i < typeParameters.Length; ++i) + { + //чтобы строка не была слишком длинной, используются сокращенные имена для типов аргументов + string paramTypeName = GetGenericTypeName_Internal(typeParameters[i], maxDepth - 1, false); + genericParams += (i == 0 ? paramTypeName : $", {paramTypeName}"); + } + return $"{typeName}<{genericParams}>"; +#else + Debug.LogWarning($"Reflection is not available, the {nameof(GetGenericTypeName_Internal)} method does not work."); + return isFull ? type.FullName : type.Name; +#endif + } + + [IN(LINE)] + public static float FastMagnitude(Vector3 v) + { + return FastSqrt(v.x * v.x + v.y * v.y + v.z * v.z); + } + [IN(LINE)] + public static unsafe float FastSqrt(float number) + { + long i; + float x2, y; + const float threehalfs = 1.5F; + + x2 = number * 0.5F; + y = number; + i = *(long*)&y; // evil floating point bit level hacking + i = 0x5f3759df - (i >> 1); // what the fuck? + y = *(float*)&i; + y = y * (threehalfs - (x2 * y * y)); // 1st iteration + //y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed + + return 1 / y; + } + [IN(LINE)] + public static int NextPow2(int v) + { + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + return ++v; + } + [IN(LINE)] + public static bool IsGizmosRender() + { + bool result = true; +#if UNITY_EDITOR + result = Handles.ShouldRenderGizmos(); +#endif + return result; + } + } +} diff --git a/Runtime/Utils/DebugXUtility.cs.meta b/Runtime/Utils/DebugXUtility.cs.meta new file mode 100644 index 0000000..5c107be --- /dev/null +++ b/Runtime/Utils/DebugXUtility.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: b2f02e57e5eea164aabe0c86b83f1b70 \ No newline at end of file diff --git a/Runtime/Internal/StaticDataLoader.cs b/Runtime/Utils/StaticDataLoader.cs similarity index 100% rename from Runtime/Internal/StaticDataLoader.cs rename to Runtime/Utils/StaticDataLoader.cs diff --git a/Runtime/Internal/StaticDataLoader.cs.meta b/Runtime/Utils/StaticDataLoader.cs.meta similarity index 100% rename from Runtime/Internal/StaticDataLoader.cs.meta rename to Runtime/Utils/StaticDataLoader.cs.meta diff --git a/Samples/Other/FakeLightMat.mat b/Samples/Other/FakeLightMat.mat index d4d7e70..bc772f3 100644 --- a/Samples/Other/FakeLightMat.mat +++ b/Samples/Other/FakeLightMat.mat @@ -54,6 +54,6 @@ Material: - _QueueControl: 0 - _QueueOffset: 0 m_Colors: - - _Color: {r: 0, g: 0.06882353, b: 0.09, a: 1} + - _Color: {r: 0, g: 0.071999975, b: 0.09, a: 1} m_BuildTextureStacks: [] m_AllowLocking: 1 diff --git a/Samples/Scripts/DebugXSample_Lines.cs b/Samples/Scripts/DebugXSample_Lines.cs index a004695..1c8d512 100644 --- a/Samples/Scripts/DebugXSample_Lines.cs +++ b/Samples/Scripts/DebugXSample_Lines.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace DCFApixels +namespace DCFApixels.DebugXCore.Samples { [SelectionBase] public class DebugXSample_Lines : MonoBehaviour diff --git a/Samples/Scripts/DebugXSample_Other.cs b/Samples/Scripts/DebugXSample_Other.cs index b7a3d97..7f59369 100644 --- a/Samples/Scripts/DebugXSample_Other.cs +++ b/Samples/Scripts/DebugXSample_Other.cs @@ -1,7 +1,6 @@ -using DCFApixels.DebugXCore; using UnityEngine; -namespace DCFApixels +namespace DCFApixels.DebugXCore.Samples { [SelectionBase] public class DebugXSample_Other : MonoBehaviour diff --git a/Samples/Scripts/DebugXSample_Primitives2D.cs b/Samples/Scripts/DebugXSample_Primitives2D.cs index a5a65f3..39c2c72 100644 --- a/Samples/Scripts/DebugXSample_Primitives2D.cs +++ b/Samples/Scripts/DebugXSample_Primitives2D.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace DCFApixels +namespace DCFApixels.DebugXCore.Samples { [SelectionBase] public class DebugXSample_Primitives2D : MonoBehaviour diff --git a/Samples/Scripts/DebugXSample_Primitives3D.cs b/Samples/Scripts/DebugXSample_Primitives3D.cs index a56c54b..af53a69 100644 --- a/Samples/Scripts/DebugXSample_Primitives3D.cs +++ b/Samples/Scripts/DebugXSample_Primitives3D.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace DCFApixels +namespace DCFApixels.DebugXCore.Samples { [SelectionBase] public class DebugXSample_Primitives3D : MonoBehaviour diff --git a/Samples/Scripts/DebugXSample_Raycasts2D.cs b/Samples/Scripts/DebugXSample_Raycasts2D.cs index 4c4fa41..9d6153c 100644 --- a/Samples/Scripts/DebugXSample_Raycasts2D.cs +++ b/Samples/Scripts/DebugXSample_Raycasts2D.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace DCFApixels +namespace DCFApixels.DebugXCore.Samples { [SelectionBase] public class DebugXSample_Raycasts2D : MonoBehaviour diff --git a/Samples/Scripts/DebugXSample_Raycasts3D.cs b/Samples/Scripts/DebugXSample_Raycasts3D.cs index 5c9ad8d..014a3c0 100644 --- a/Samples/Scripts/DebugXSample_Raycasts3D.cs +++ b/Samples/Scripts/DebugXSample_Raycasts3D.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace DCFApixels +namespace DCFApixels.DebugXCore.Samples { [SelectionBase] public class DebugXSample_Raycasts3D : MonoBehaviour