polishing

This commit is contained in:
DCFApixels 2025-02-24 11:06:15 +08:00
parent 9824936c13
commit 1d97c637ff
4 changed files with 83 additions and 79 deletions

View File

@ -21,9 +21,6 @@ namespace DCFApixels
{ {
using IN = System.Runtime.CompilerServices.MethodImplAttribute; using IN = System.Runtime.CompilerServices.MethodImplAttribute;
#if UNITY_EDITOR
// [InitializeOnLoad]
#endif
public static unsafe partial class DebugX public static unsafe partial class DebugX
{ {
private static PauseStateX _pauseState = PauseStateX.Unpaused; private static PauseStateX _pauseState = PauseStateX.Unpaused;
@ -37,81 +34,6 @@ namespace DCFApixels
private static ulong _renderTicks = 100; private static ulong _renderTicks = 100;
private static ulong _timeTicks = 0; private static ulong _timeTicks = 0;
#region Globals
private const string GlobalTimeScalePrefName = "DCFApixels.DebugX.TimeScale";
private static float _timeScaleCache;
public static float GlobalTimeScale
{
get { return _timeScaleCache; }
set
{
value = Mathf.Max(0f, value);
if (_timeScaleCache == value) { return; }
_timeScaleCache = value;
#if UNITY_EDITOR
EditorPrefs.SetFloat(GlobalTimeScalePrefName, value);
#endif
}
}
private const string GlobalDotSizePrefName = "DCFApixels.DebugX.DotSize";
private static float _dotSizeCache;
public static float GlobalDotSize
{
get { return _dotSizeCache; }
set
{
if (_dotSizeCache == value) { return; }
_dotSizeCache = value;
Shader.SetGlobalFloat(GlobalDotSizePropertyID, _dotSizeCache);
#if UNITY_EDITOR
EditorPrefs.SetFloat(GlobalDotSizePrefName, _dotSizeCache);
#endif
}
}
private const string GlobalColorPrefName = "DCFApixels.DebugX.Color";
private static Color _globalColorCache;
public static Color GlobalColor
{
get { return _globalColorCache; }
set
{
if (_globalColorCache == value) { return; }
_globalColorCache = value;
Shader.SetGlobalVector(nameID: GlobalColorPropertyID, _globalColorCache);
Color32 c32 = (Color32)value;
var record = *(int*)&c32;
#if UNITY_EDITOR
EditorPrefs.SetInt(GlobalColorPrefName, record);
#endif
}
}
public static void ResetGlobals()
{
#if UNITY_EDITOR
EditorPrefs.DeleteKey(GlobalTimeScalePrefName);
EditorPrefs.DeleteKey(GlobalDotSizePrefName);
EditorPrefs.DeleteKey(GlobalColorPrefName);
_dotSizeCache = default;
_timeScaleCache = default;
_globalColorCache = default;
InitGlobals();
#endif
}
public static void InitGlobals()
{
GlobalTimeScale = 1;
GlobalDotSize = 1;
GlobalColor = Color.white;
#if UNITY_EDITOR
GlobalTimeScale = EditorPrefs.GetFloat(GlobalTimeScalePrefName, 1f);
GlobalDotSize = EditorPrefs.GetFloat(GlobalDotSizePrefName, 1f);
var colorCode = EditorPrefs.GetInt(GlobalColorPrefName, -1);
GlobalColor = (Color)(*(Color32*)&colorCode);
#endif
}
#endregion
#region Other #region Other
public static void ClearAllGizmos() public static void ClearAllGizmos()
{ {
@ -137,7 +59,6 @@ namespace DCFApixels
_pauseState = obj == PauseState.Paused ? PauseStateX.Paused : PauseStateX.PreUnpaused; _pauseState = obj == PauseState.Paused ? PauseStateX.Paused : PauseStateX.PreUnpaused;
} }
#endif #endif
#endregion #endregion
#region ctor #region ctor

83
Runtime/DebugX.globals.cs Normal file
View File

@ -0,0 +1,83 @@
using UnityEditor;
using UnityEngine;
namespace DCFApixels
{
public static unsafe partial class DebugX
{
#region Globals
private const string GlobalTimeScalePrefName = "DCFApixels.DebugX.TimeScale";
private static float _timeScaleCache;
public static float GlobalTimeScale
{
get { return _timeScaleCache; }
set
{
value = Mathf.Max(0f, value);
if (_timeScaleCache == value) { return; }
_timeScaleCache = value;
#if UNITY_EDITOR
EditorPrefs.SetFloat(GlobalTimeScalePrefName, value);
#endif
}
}
private const string GlobalDotSizePrefName = "DCFApixels.DebugX.DotSize";
private static float _dotSizeCache;
public static float GlobalDotSize
{
get { return _dotSizeCache; }
set
{
if (_dotSizeCache == value) { return; }
_dotSizeCache = value;
Shader.SetGlobalFloat(GlobalDotSizePropertyID, _dotSizeCache);
#if UNITY_EDITOR
EditorPrefs.SetFloat(GlobalDotSizePrefName, _dotSizeCache);
#endif
}
}
private const string GlobalColorPrefName = "DCFApixels.DebugX.Color";
private static Color _globalColorCache;
public static Color GlobalColor
{
get { return _globalColorCache; }
set
{
if (_globalColorCache == value) { return; }
_globalColorCache = value;
Shader.SetGlobalVector(nameID: GlobalColorPropertyID, _globalColorCache);
Color32 c32 = (Color32)value;
var record = *(int*)&c32;
#if UNITY_EDITOR
EditorPrefs.SetInt(GlobalColorPrefName, record);
#endif
}
}
public static void ResetGlobals()
{
#if UNITY_EDITOR
EditorPrefs.DeleteKey(GlobalTimeScalePrefName);
EditorPrefs.DeleteKey(GlobalDotSizePrefName);
EditorPrefs.DeleteKey(GlobalColorPrefName);
_dotSizeCache = default;
_timeScaleCache = default;
_globalColorCache = default;
InitGlobals();
#endif
}
public static void InitGlobals()
{
GlobalTimeScale = 1;
GlobalDotSize = 1;
GlobalColor = Color.white;
#if UNITY_EDITOR
GlobalTimeScale = EditorPrefs.GetFloat(GlobalTimeScalePrefName, 1f);
GlobalDotSize = EditorPrefs.GetFloat(GlobalDotSizePrefName, 1f);
var colorCode = EditorPrefs.GetInt(GlobalColorPrefName, -1);
GlobalColor = (Color)(*(Color32*)&colorCode);
#endif
}
#endregion
}
}