diff --git a/Runtime/Utils/DebugX.assets.cs b/Runtime/DebugX.assets.cs similarity index 100% rename from Runtime/Utils/DebugX.assets.cs rename to Runtime/DebugX.assets.cs diff --git a/Runtime/Utils/DebugX.assets.cs.meta b/Runtime/DebugX.assets.cs.meta similarity index 100% rename from Runtime/Utils/DebugX.assets.cs.meta rename to Runtime/DebugX.assets.cs.meta diff --git a/Runtime/DebugX.cs b/Runtime/DebugX.cs index de0c2a3..9760607 100644 --- a/Runtime/DebugX.cs +++ b/Runtime/DebugX.cs @@ -21,9 +21,6 @@ namespace DCFApixels { using IN = System.Runtime.CompilerServices.MethodImplAttribute; -#if UNITY_EDITOR - // [InitializeOnLoad] -#endif public static unsafe partial class DebugX { private static PauseStateX _pauseState = PauseStateX.Unpaused; @@ -37,81 +34,6 @@ namespace DCFApixels private static ulong _renderTicks = 100; 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 public static void ClearAllGizmos() { @@ -137,7 +59,6 @@ namespace DCFApixels _pauseState = obj == PauseState.Paused ? PauseStateX.Paused : PauseStateX.PreUnpaused; } #endif - #endregion #region ctor diff --git a/Runtime/DebugX.globals.cs b/Runtime/DebugX.globals.cs new file mode 100644 index 0000000..6f12871 --- /dev/null +++ b/Runtime/DebugX.globals.cs @@ -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 + } +} \ No newline at end of file