polishing

This commit is contained in:
DCFApixels 2025-02-24 17:59:44 +08:00
parent e6e010641f
commit 5274939632
10 changed files with 131 additions and 53 deletions

View File

@ -1,5 +1,7 @@
#if UNITY_EDITOR #if UNITY_EDITOR
using UnityEditor; using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Compilation;
using UnityEngine; using UnityEngine;
namespace DCFApixels.DebugXCore.Internal namespace DCFApixels.DebugXCore.Internal
@ -11,8 +13,20 @@ namespace DCFApixels.DebugXCore.Internal
{ {
DebugXSettings window = (DebugXSettings)EditorWindow.GetWindow(typeof(DebugXSettings)); DebugXSettings window = (DebugXSettings)EditorWindow.GetWindow(typeof(DebugXSettings));
window.Show(); window.Show();
window._isHasDisableDebugXInBuildSymbols = null;
CompilationPipeline.compilationFinished -= CompilationPipeline_compilationFinished;
CompilationPipeline.compilationFinished += CompilationPipeline_compilationFinished;
} }
private static void CompilationPipeline_compilationFinished(object obj)
{
_isCompilation = false;
}
private static bool _isCompilation;
private bool? _isHasDisableDebugXInBuildSymbols = false;
private const string DEFINE_NAME = nameof(DebugX.DISABLE_DEBUGX_INBUILD);
private void OnGUI() private void OnGUI()
{ {
float tmpValue; float tmpValue;
@ -38,6 +52,60 @@ namespace DCFApixels.DebugXCore.Internal
color.a = EditorGUILayout.Slider(DebugX.GlobalColor.a, 0, 1); color.a = EditorGUILayout.Slider(DebugX.GlobalColor.a, 0, 1);
DebugX.GlobalColor = color; DebugX.GlobalColor = color;
if (_isCompilation == false)
{
if (_isHasDisableDebugXInBuildSymbols == null)
{
BuildTargetGroup group = EditorUserBuildSettings.selectedBuildTargetGroup;
#if UNITY_6000_0_OR_NEWER
string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group));
#else
string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
#endif
_isHasDisableDebugXInBuildSymbols = symbolsString.Contains(DEFINE_NAME);
}
EditorGUI.BeginChangeCheck();
_isHasDisableDebugXInBuildSymbols = !EditorGUILayout.ToggleLeft("Show Gizmos in Build", !_isHasDisableDebugXInBuildSymbols.Value);
if (EditorGUI.EndChangeCheck())
{
BuildTargetGroup group = EditorUserBuildSettings.selectedBuildTargetGroup;
#if UNITY_6000_0_OR_NEWER
string symbolsString = PlayerSettings.GetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group));
#else
string symbolsString = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
#endif
if (symbolsString.Contains(DEFINE_NAME) == false)
{
symbolsString = symbolsString + ", " + DEFINE_NAME;
}
else
{
symbolsString = symbolsString.Replace(DEFINE_NAME, "");
}
#if UNITY_6000_0_OR_NEWER
PlayerSettings.SetScriptingDefineSymbols(NamedBuildTarget.FromBuildTargetGroup(group), symbolsString);
#else
PlayerSettings.SetScriptingDefineSymbolsForGroup(group, symbolsString);
#endif
_isCompilation = true;
}
}
else
{
_isHasDisableDebugXInBuildSymbols = null;
GUI.enabled = false;
EditorGUILayout.ToggleLeft("Show Gizmos in Build (Locked for compilation)", false);
GUI.enabled = true;
}
if (GUILayout.Button("Reset")) if (GUILayout.Button("Reset"))
{ {
DebugX.ResetGlobals(); DebugX.ResetGlobals();

View File

@ -12,17 +12,28 @@ namespace DCFApixels
private const float DOT_SIZE = DOT_RADIUS * 2f; private const float DOT_SIZE = DOT_RADIUS * 2f;
private const float DOT_RADIUS = 0.05f; private const float DOT_RADIUS = 0.05f;
private const float BackfaceAlphaMultiplier = 0.3f;
private const string GLOBAL_TIME_SCALE_PREF_NAME = "DCFApixels.DebugX.TimeScale";
private const string GLOBAL_DOT_SIZE_PREF_NAME = "DCFApixels.DebugX.DotSize";
private const string GLOBAL_COLOR_PREF_NAME = "DCFApixels.DebugX.Color";
private readonly static int GlobalDotSizePropertyID = Shader.PropertyToID("_DebugX_GlobalDotSize");
private readonly static int GlobalColorPropertyID = Shader.PropertyToID("_DebugX_GlobalColor");
internal readonly static int ColorPropertyID = Shader.PropertyToID("_Color"); internal readonly static int ColorPropertyID = Shader.PropertyToID("_Color");
internal readonly static int GlobalDotSizePropertyID = Shader.PropertyToID("_DebugX_GlobalDotSize");
internal readonly static int GlobalColorPropertyID = Shader.PropertyToID("_DebugX_GlobalColor");
private readonly static bool IsSRP;
private readonly static bool IsSupportsComputeShaders = SystemInfo.supportsComputeShaders;
public const float IMMEDIATE_DURATION = -1; public const float IMMEDIATE_DURATION = -1;
public readonly static bool IsSRP;
public readonly static bool IsSupportsComputeShaders = SystemInfo.supportsComputeShaders;
public const bool DISABLE_DEBUGX_INBUILD =
#if DISABLE_DEBUGX_INBUILD
true;
#else
false;
#endif
private enum PauseStateX private enum PauseStateX
{ {
Unpaused = 0, Unpaused = 0,

View File

@ -374,13 +374,17 @@ namespace DCFApixels
[IN(LINE)] [IN(LINE)]
public DrawHandler Gizmo<T>(T value) where T : IGizmo<T> public DrawHandler Gizmo<T>(T value) where T : IGizmo<T>
{ {
#if UNITY_EDITOR || !DISABLE_DEBUGX_INBUILD
GetCurrentContextController().Add(value, Duration, Color); GetCurrentContextController().Add(value, Duration, Color);
#endif
return this; return this;
} }
[IN(LINE)] [IN(LINE)]
public DrawHandler Gizmos<T>(ReadOnlySpan<T> values) where T : IGizmo<T> public DrawHandler Gizmos<T>(ReadOnlySpan<T> values) where T : IGizmo<T>
{ {
#if UNITY_EDITOR || !DISABLE_DEBUGX_INBUILD
GetCurrentContextController().AddRange(values, Duration, Color); GetCurrentContextController().AddRange(values, Duration, Color);
#endif
return this; return this;
} }
} }
@ -411,7 +415,7 @@ namespace DCFApixels
} }
return _currenRenderContextControler; return _currenRenderContextControler;
} }
#endregion #endregion
#region RenderContextControler #region RenderContextControler

View File

@ -7,7 +7,6 @@ namespace DCFApixels
{ {
public static unsafe partial class DebugX public static unsafe partial class DebugX
{ {
private const string GlobalTimeScalePrefName = "DCFApixels.DebugX.TimeScale";
private static float _timeScaleCache; private static float _timeScaleCache;
public static float GlobalTimeScale public static float GlobalTimeScale
{ {
@ -18,11 +17,10 @@ namespace DCFApixels
if (_timeScaleCache == value) { return; } if (_timeScaleCache == value) { return; }
_timeScaleCache = value; _timeScaleCache = value;
#if UNITY_EDITOR #if UNITY_EDITOR
EditorPrefs.SetFloat(GlobalTimeScalePrefName, value); EditorPrefs.SetFloat(GLOBAL_TIME_SCALE_PREF_NAME, value);
#endif #endif
} }
} }
private const string GlobalDotSizePrefName = "DCFApixels.DebugX.DotSize";
private static float _dotSizeCache; private static float _dotSizeCache;
public static float GlobalDotSize public static float GlobalDotSize
{ {
@ -33,11 +31,10 @@ namespace DCFApixels
_dotSizeCache = value; _dotSizeCache = value;
Shader.SetGlobalFloat(GlobalDotSizePropertyID, _dotSizeCache); Shader.SetGlobalFloat(GlobalDotSizePropertyID, _dotSizeCache);
#if UNITY_EDITOR #if UNITY_EDITOR
EditorPrefs.SetFloat(GlobalDotSizePrefName, _dotSizeCache); EditorPrefs.SetFloat(GLOBAL_DOT_SIZE_PREF_NAME, _dotSizeCache);
#endif #endif
} }
} }
private const string GlobalColorPrefName = "DCFApixels.DebugX.Color";
private static Color _globalColorCache; private static Color _globalColorCache;
public static Color GlobalColor public static Color GlobalColor
{ {
@ -51,16 +48,16 @@ namespace DCFApixels
Color32 c32 = (Color32)value; Color32 c32 = (Color32)value;
var record = *(int*)&c32; var record = *(int*)&c32;
#if UNITY_EDITOR #if UNITY_EDITOR
EditorPrefs.SetInt(GlobalColorPrefName, record); EditorPrefs.SetInt(GLOBAL_COLOR_PREF_NAME, record);
#endif #endif
} }
} }
public static void ResetGlobals() public static void ResetGlobals()
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
EditorPrefs.DeleteKey(GlobalTimeScalePrefName); EditorPrefs.DeleteKey(GLOBAL_TIME_SCALE_PREF_NAME);
EditorPrefs.DeleteKey(GlobalDotSizePrefName); EditorPrefs.DeleteKey(GLOBAL_DOT_SIZE_PREF_NAME);
EditorPrefs.DeleteKey(GlobalColorPrefName); EditorPrefs.DeleteKey(GLOBAL_COLOR_PREF_NAME);
#endif #endif
_dotSizeCache = default; _dotSizeCache = default;
_timeScaleCache = default; _timeScaleCache = default;
@ -73,9 +70,9 @@ namespace DCFApixels
GlobalDotSize = 1; GlobalDotSize = 1;
GlobalColor = Color.white; GlobalColor = Color.white;
#if UNITY_EDITOR #if UNITY_EDITOR
GlobalTimeScale = EditorPrefs.GetFloat(GlobalTimeScalePrefName, 1f); GlobalTimeScale = EditorPrefs.GetFloat(GLOBAL_TIME_SCALE_PREF_NAME, 1f);
GlobalDotSize = EditorPrefs.GetFloat(GlobalDotSizePrefName, 1f); GlobalDotSize = EditorPrefs.GetFloat(GLOBAL_DOT_SIZE_PREF_NAME, 1f);
var colorCode = EditorPrefs.GetInt(GlobalColorPrefName, -1); var colorCode = EditorPrefs.GetInt(GLOBAL_COLOR_PREF_NAME, -1);
GlobalColor = (Color)(*(Color32*)&colorCode); GlobalColor = (Color)(*(Color32*)&colorCode);
#endif #endif
} }

View File

@ -1,9 +1,9 @@
//#undef DEBUG //#undef DEBUG
using DCFApixels.DebugXCore;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
using UnityEngine; using UnityEngine;
using UnityEngine.Rendering; using UnityEngine.Rendering;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
using DCFApixels.DebugXCore;
using DCFApixels.DebugXCore.Internal; using DCFApixels.DebugXCore.Internal;
#if UNITY_EDITOR #if UNITY_EDITOR
using UnityEditor; using UnityEditor;

View File

@ -1,7 +1,7 @@
//#undef DEBUG //#undef DEBUG
using DCFApixels.DebugXCore;
using UnityEngine; using UnityEngine;
using UnityEngine.Rendering; using UnityEngine.Rendering;
using DCFApixels.DebugXCore;
namespace DCFApixels namespace DCFApixels
{ {

View File

@ -1,8 +1,8 @@
//#undef DEBUG //#undef DEBUG
using DCFApixels.DebugXCore;
using System; using System;
using UnityEngine; using UnityEngine;
using UnityEngine.Rendering; using UnityEngine.Rendering;
using DCFApixels.DebugXCore;
namespace DCFApixels namespace DCFApixels
{ {

View File

@ -1,6 +1,6 @@
//#undef DEBUG //#undef DEBUG
using DCFApixels.DebugXCore.Internal;
using UnityEngine; using UnityEngine;
using DCFApixels.DebugXCore.Internal;
namespace DCFApixels namespace DCFApixels
{ {

View File

@ -1,15 +1,15 @@
using System; using System;
using UnityEngine;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using UnityEngine;
#if UNITY_EDITOR #if UNITY_EDITOR
using UnityEditor; using UnityEditor;
#endif #endif
namespace DCFApixels.DebugXCore namespace DCFApixels.DebugXCore
{ {
using IN = System.Runtime.CompilerServices.MethodImplAttribute; using IN = MethodImplAttribute;
public static class DebugXUtility public static class DebugXUtility
{ {
private const MethodImplOptions LINE = MethodImplOptions.AggressiveInlining; private const MethodImplOptions LINE = MethodImplOptions.AggressiveInlining;

View File

@ -1,6 +1,4 @@
using UnityEngine; using UnityEngine;
using static DCFApixels.DebugX;
namespace DCFApixels.DebugXCore namespace DCFApixels.DebugXCore
{ {
public interface IStaticData { } public interface IStaticData { }
@ -19,105 +17,105 @@ namespace DCFApixels.DebugXCore
public readonly struct LitMat : IStaticMaterial public readonly struct LitMat : IStaticMaterial
{ {
public int GetExecuteOrder() => 0; public int GetExecuteOrder() => 0;
public Material GetMaterial() => Materials.Lit; public Material GetMaterial() => DebugX.Materials.Lit;
} }
public readonly struct UnlitMat : IStaticMaterial public readonly struct UnlitMat : IStaticMaterial
{ {
public int GetExecuteOrder() => 100_000; public int GetExecuteOrder() => 100_000;
public Material GetMaterial() => Materials.Unlit; public Material GetMaterial() => DebugX.Materials.Unlit;
} }
public readonly struct BillboardMat : IStaticMaterial public readonly struct BillboardMat : IStaticMaterial
{ {
public int GetExecuteOrder() => 200_000; public int GetExecuteOrder() => 200_000;
public Material GetMaterial() => Materials.Billboard; public Material GetMaterial() => DebugX.Materials.Billboard;
} }
public readonly struct DotMat : IStaticMaterial public readonly struct DotMat : IStaticMaterial
{ {
public int GetExecuteOrder() => 300_000; public int GetExecuteOrder() => 300_000;
public Material GetMaterial() => Materials.Dot; public Material GetMaterial() => DebugX.Materials.Dot;
} }
public readonly struct GeometryUnlitMat : IStaticMaterial public readonly struct GeometryUnlitMat : IStaticMaterial
{ {
public int GetExecuteOrder() => 1_000_000; public int GetExecuteOrder() => 1_000_000;
public Material GetMaterial() => Materials.Unlit; public Material GetMaterial() => DebugX.Materials.Unlit;
} }
public readonly struct WireMat : IStaticMaterial public readonly struct WireMat : IStaticMaterial
{ {
public int GetExecuteOrder() => 1_000_000; public int GetExecuteOrder() => 1_000_000;
public Material GetMaterial() => Materials.Wire; public Material GetMaterial() => DebugX.Materials.Wire;
} }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public readonly struct SphereMesh : IStaticMesh public readonly struct SphereMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.Sphere; public Mesh GetMesh() => DebugX.Meshes.Sphere;
} }
public readonly struct CubeMesh : IStaticMesh public readonly struct CubeMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.Cube; public Mesh GetMesh() => DebugX.Meshes.Cube;
} }
public readonly struct QuadMesh : IStaticMesh public readonly struct QuadMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.Quad; public Mesh GetMesh() => DebugX.Meshes.Quad;
} }
public readonly struct CircleMesh : IStaticMesh public readonly struct CircleMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.Circle; public Mesh GetMesh() => DebugX.Meshes.Circle;
} }
public readonly struct CapsuleBodyMesh : IStaticMesh public readonly struct CapsuleBodyMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.CapsuleBody; public Mesh GetMesh() => DebugX.Meshes.CapsuleBody;
} }
public readonly struct CapsuleHeadMesh : IStaticMesh public readonly struct CapsuleHeadMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.CapsuleHead; public Mesh GetMesh() => DebugX.Meshes.CapsuleHead;
} }
public readonly struct FlatCapsuleBodyMesh : IStaticMesh public readonly struct FlatCapsuleBodyMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.FlatCapsuleBody; public Mesh GetMesh() => DebugX.Meshes.FlatCapsuleBody;
} }
public readonly struct FlatCapsuleHeadMesh : IStaticMesh public readonly struct FlatCapsuleHeadMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.FlatCapsuleHead; public Mesh GetMesh() => DebugX.Meshes.FlatCapsuleHead;
} }
public readonly struct ArrowMesh : IStaticMesh public readonly struct ArrowMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.Arrow; public Mesh GetMesh() => DebugX.Meshes.Arrow;
} }
public readonly struct DotMesh : IStaticMesh public readonly struct DotMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.Dot; public Mesh GetMesh() => DebugX.Meshes.Dot;
} }
public readonly struct DotQuadMesh : IStaticMesh public readonly struct DotQuadMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.DotQuad; public Mesh GetMesh() => DebugX.Meshes.DotQuad;
} }
public readonly struct DotDiamondMesh : IStaticMesh public readonly struct DotDiamondMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.DotDiamond; public Mesh GetMesh() => DebugX.Meshes.DotDiamond;
} }
public readonly struct DotCrossMesh : IStaticMesh public readonly struct DotCrossMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.DotCross; public Mesh GetMesh() => DebugX.Meshes.DotCross;
} }
public readonly struct WireLineMesh : IStaticMesh public readonly struct WireLineMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.WireLine; public Mesh GetMesh() => DebugX.Meshes.WireLine;
} }
public readonly struct WireCubeMesh : IStaticMesh public readonly struct WireCubeMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.WireCube; public Mesh GetMesh() => DebugX.Meshes.WireCube;
} }
public readonly struct WireArcMesh : IStaticMesh public readonly struct WireArcMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.WireArc; public Mesh GetMesh() => DebugX.Meshes.WireArc;
} }
public readonly struct WireCircleMesh : IStaticMesh public readonly struct WireCircleMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.WireCircle; public Mesh GetMesh() => DebugX.Meshes.WireCircle;
} }
public readonly struct WireSphereMesh : IStaticMesh public readonly struct WireSphereMesh : IStaticMesh
{ {
public Mesh GetMesh() => Meshes.WireSphere; public Mesh GetMesh() => DebugX.Meshes.WireSphere;
} }
} }