mirror of
https://github.com/DCFApixels/Unity-DebugX.git
synced 2025-09-18 01:54:37 +08:00
polishing
This commit is contained in:
parent
e6e010641f
commit
5274939632
@ -1,5 +1,7 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Compilation;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DCFApixels.DebugXCore.Internal
|
||||
@ -11,8 +13,20 @@ namespace DCFApixels.DebugXCore.Internal
|
||||
{
|
||||
DebugXSettings window = (DebugXSettings)EditorWindow.GetWindow(typeof(DebugXSettings));
|
||||
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()
|
||||
{
|
||||
float tmpValue;
|
||||
@ -38,6 +52,60 @@ namespace DCFApixels.DebugXCore.Internal
|
||||
color.a = EditorGUILayout.Slider(DebugX.GlobalColor.a, 0, 1);
|
||||
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"))
|
||||
{
|
||||
DebugX.ResetGlobals();
|
||||
|
@ -12,17 +12,28 @@ namespace DCFApixels
|
||||
|
||||
private const float DOT_SIZE = DOT_RADIUS * 2f;
|
||||
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 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 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
|
||||
{
|
||||
Unpaused = 0,
|
||||
|
@ -374,13 +374,17 @@ namespace DCFApixels
|
||||
[IN(LINE)]
|
||||
public DrawHandler Gizmo<T>(T value) where T : IGizmo<T>
|
||||
{
|
||||
#if UNITY_EDITOR || !DISABLE_DEBUGX_INBUILD
|
||||
GetCurrentContextController().Add(value, Duration, Color);
|
||||
#endif
|
||||
return this;
|
||||
}
|
||||
[IN(LINE)]
|
||||
public DrawHandler Gizmos<T>(ReadOnlySpan<T> values) where T : IGizmo<T>
|
||||
{
|
||||
#if UNITY_EDITOR || !DISABLE_DEBUGX_INBUILD
|
||||
GetCurrentContextController().AddRange(values, Duration, Color);
|
||||
#endif
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@ -411,7 +415,7 @@ namespace DCFApixels
|
||||
}
|
||||
return _currenRenderContextControler;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
|
||||
#region RenderContextControler
|
||||
|
@ -7,7 +7,6 @@ namespace DCFApixels
|
||||
{
|
||||
public static unsafe partial class DebugX
|
||||
{
|
||||
private const string GlobalTimeScalePrefName = "DCFApixels.DebugX.TimeScale";
|
||||
private static float _timeScaleCache;
|
||||
public static float GlobalTimeScale
|
||||
{
|
||||
@ -18,11 +17,10 @@ namespace DCFApixels
|
||||
if (_timeScaleCache == value) { return; }
|
||||
_timeScaleCache = value;
|
||||
#if UNITY_EDITOR
|
||||
EditorPrefs.SetFloat(GlobalTimeScalePrefName, value);
|
||||
EditorPrefs.SetFloat(GLOBAL_TIME_SCALE_PREF_NAME, value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
private const string GlobalDotSizePrefName = "DCFApixels.DebugX.DotSize";
|
||||
private static float _dotSizeCache;
|
||||
public static float GlobalDotSize
|
||||
{
|
||||
@ -33,11 +31,10 @@ namespace DCFApixels
|
||||
_dotSizeCache = value;
|
||||
Shader.SetGlobalFloat(GlobalDotSizePropertyID, _dotSizeCache);
|
||||
#if UNITY_EDITOR
|
||||
EditorPrefs.SetFloat(GlobalDotSizePrefName, _dotSizeCache);
|
||||
EditorPrefs.SetFloat(GLOBAL_DOT_SIZE_PREF_NAME, _dotSizeCache);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
private const string GlobalColorPrefName = "DCFApixels.DebugX.Color";
|
||||
private static Color _globalColorCache;
|
||||
public static Color GlobalColor
|
||||
{
|
||||
@ -51,16 +48,16 @@ namespace DCFApixels
|
||||
Color32 c32 = (Color32)value;
|
||||
var record = *(int*)&c32;
|
||||
#if UNITY_EDITOR
|
||||
EditorPrefs.SetInt(GlobalColorPrefName, record);
|
||||
EditorPrefs.SetInt(GLOBAL_COLOR_PREF_NAME, record);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
public static void ResetGlobals()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EditorPrefs.DeleteKey(GlobalTimeScalePrefName);
|
||||
EditorPrefs.DeleteKey(GlobalDotSizePrefName);
|
||||
EditorPrefs.DeleteKey(GlobalColorPrefName);
|
||||
EditorPrefs.DeleteKey(GLOBAL_TIME_SCALE_PREF_NAME);
|
||||
EditorPrefs.DeleteKey(GLOBAL_DOT_SIZE_PREF_NAME);
|
||||
EditorPrefs.DeleteKey(GLOBAL_COLOR_PREF_NAME);
|
||||
#endif
|
||||
_dotSizeCache = default;
|
||||
_timeScaleCache = default;
|
||||
@ -73,9 +70,9 @@ namespace DCFApixels
|
||||
GlobalDotSize = 1;
|
||||
GlobalColor = Color.white;
|
||||
#if UNITY_EDITOR
|
||||
GlobalTimeScale = EditorPrefs.GetFloat(GlobalTimeScalePrefName, 1f);
|
||||
GlobalDotSize = EditorPrefs.GetFloat(GlobalDotSizePrefName, 1f);
|
||||
var colorCode = EditorPrefs.GetInt(GlobalColorPrefName, -1);
|
||||
GlobalTimeScale = EditorPrefs.GetFloat(GLOBAL_TIME_SCALE_PREF_NAME, 1f);
|
||||
GlobalDotSize = EditorPrefs.GetFloat(GLOBAL_DOT_SIZE_PREF_NAME, 1f);
|
||||
var colorCode = EditorPrefs.GetInt(GLOBAL_COLOR_PREF_NAME, -1);
|
||||
GlobalColor = (Color)(*(Color32*)&colorCode);
|
||||
#endif
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
//#undef DEBUG
|
||||
using DCFApixels.DebugXCore;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using Unity.Jobs;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using Unity.Jobs;
|
||||
using DCFApixels.DebugXCore;
|
||||
using DCFApixels.DebugXCore.Internal;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
|
@ -1,7 +1,7 @@
|
||||
//#undef DEBUG
|
||||
using DCFApixels.DebugXCore;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using DCFApixels.DebugXCore;
|
||||
|
||||
namespace DCFApixels
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
//#undef DEBUG
|
||||
using DCFApixels.DebugXCore;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using DCFApixels.DebugXCore;
|
||||
|
||||
namespace DCFApixels
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
//#undef DEBUG
|
||||
using DCFApixels.DebugXCore.Internal;
|
||||
using UnityEngine;
|
||||
using DCFApixels.DebugXCore.Internal;
|
||||
|
||||
namespace DCFApixels
|
||||
{
|
||||
|
@ -1,15 +1,15 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace DCFApixels.DebugXCore
|
||||
{
|
||||
using IN = System.Runtime.CompilerServices.MethodImplAttribute;
|
||||
using IN = MethodImplAttribute;
|
||||
public static class DebugXUtility
|
||||
{
|
||||
private const MethodImplOptions LINE = MethodImplOptions.AggressiveInlining;
|
||||
|
@ -1,6 +1,4 @@
|
||||
using UnityEngine;
|
||||
using static DCFApixels.DebugX;
|
||||
|
||||
namespace DCFApixels.DebugXCore
|
||||
{
|
||||
public interface IStaticData { }
|
||||
@ -19,105 +17,105 @@ namespace DCFApixels.DebugXCore
|
||||
public readonly struct LitMat : IStaticMaterial
|
||||
{
|
||||
public int GetExecuteOrder() => 0;
|
||||
public Material GetMaterial() => Materials.Lit;
|
||||
public Material GetMaterial() => DebugX.Materials.Lit;
|
||||
}
|
||||
public readonly struct UnlitMat : IStaticMaterial
|
||||
{
|
||||
public int GetExecuteOrder() => 100_000;
|
||||
public Material GetMaterial() => Materials.Unlit;
|
||||
public Material GetMaterial() => DebugX.Materials.Unlit;
|
||||
}
|
||||
public readonly struct BillboardMat : IStaticMaterial
|
||||
{
|
||||
public int GetExecuteOrder() => 200_000;
|
||||
public Material GetMaterial() => Materials.Billboard;
|
||||
public Material GetMaterial() => DebugX.Materials.Billboard;
|
||||
}
|
||||
public readonly struct DotMat : IStaticMaterial
|
||||
{
|
||||
public int GetExecuteOrder() => 300_000;
|
||||
public Material GetMaterial() => Materials.Dot;
|
||||
public Material GetMaterial() => DebugX.Materials.Dot;
|
||||
}
|
||||
public readonly struct GeometryUnlitMat : IStaticMaterial
|
||||
{
|
||||
public int GetExecuteOrder() => 1_000_000;
|
||||
public Material GetMaterial() => Materials.Unlit;
|
||||
public Material GetMaterial() => DebugX.Materials.Unlit;
|
||||
}
|
||||
public readonly struct WireMat : IStaticMaterial
|
||||
{
|
||||
public int GetExecuteOrder() => 1_000_000;
|
||||
public Material GetMaterial() => Materials.Wire;
|
||||
public Material GetMaterial() => DebugX.Materials.Wire;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public readonly struct SphereMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.Sphere;
|
||||
public Mesh GetMesh() => DebugX.Meshes.Sphere;
|
||||
}
|
||||
public readonly struct CubeMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.Cube;
|
||||
public Mesh GetMesh() => DebugX.Meshes.Cube;
|
||||
}
|
||||
public readonly struct QuadMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.Quad;
|
||||
public Mesh GetMesh() => DebugX.Meshes.Quad;
|
||||
}
|
||||
public readonly struct CircleMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.Circle;
|
||||
public Mesh GetMesh() => DebugX.Meshes.Circle;
|
||||
}
|
||||
public readonly struct CapsuleBodyMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.CapsuleBody;
|
||||
public Mesh GetMesh() => DebugX.Meshes.CapsuleBody;
|
||||
}
|
||||
public readonly struct CapsuleHeadMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.CapsuleHead;
|
||||
public Mesh GetMesh() => DebugX.Meshes.CapsuleHead;
|
||||
}
|
||||
public readonly struct FlatCapsuleBodyMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.FlatCapsuleBody;
|
||||
public Mesh GetMesh() => DebugX.Meshes.FlatCapsuleBody;
|
||||
}
|
||||
public readonly struct FlatCapsuleHeadMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.FlatCapsuleHead;
|
||||
public Mesh GetMesh() => DebugX.Meshes.FlatCapsuleHead;
|
||||
}
|
||||
public readonly struct ArrowMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.Arrow;
|
||||
public Mesh GetMesh() => DebugX.Meshes.Arrow;
|
||||
}
|
||||
public readonly struct DotMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.Dot;
|
||||
public Mesh GetMesh() => DebugX.Meshes.Dot;
|
||||
}
|
||||
public readonly struct DotQuadMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.DotQuad;
|
||||
public Mesh GetMesh() => DebugX.Meshes.DotQuad;
|
||||
}
|
||||
public readonly struct DotDiamondMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.DotDiamond;
|
||||
public Mesh GetMesh() => DebugX.Meshes.DotDiamond;
|
||||
}
|
||||
public readonly struct DotCrossMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.DotCross;
|
||||
public Mesh GetMesh() => DebugX.Meshes.DotCross;
|
||||
}
|
||||
public readonly struct WireLineMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.WireLine;
|
||||
public Mesh GetMesh() => DebugX.Meshes.WireLine;
|
||||
}
|
||||
public readonly struct WireCubeMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.WireCube;
|
||||
public Mesh GetMesh() => DebugX.Meshes.WireCube;
|
||||
}
|
||||
public readonly struct WireArcMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.WireArc;
|
||||
public Mesh GetMesh() => DebugX.Meshes.WireArc;
|
||||
}
|
||||
public readonly struct WireCircleMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.WireCircle;
|
||||
public Mesh GetMesh() => DebugX.Meshes.WireCircle;
|
||||
}
|
||||
public readonly struct WireSphereMesh : IStaticMesh
|
||||
{
|
||||
public Mesh GetMesh() => Meshes.WireSphere;
|
||||
public Mesh GetMesh() => DebugX.Meshes.WireSphere;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user