From 40fa4d715153bcf1da01a6bb81a87da5c14d3341 Mon Sep 17 00:00:00 2001 From: Ejlersen Date: Fri, 28 Jan 2022 21:48:29 +0100 Subject: [PATCH] 1.3.2: Added min & max values for time slider and modifiable in settings --- Editor/Toolbar/Settings/ToolbarSettings.cs | 14 +++++++++++ .../Settings/ToolbarSettingsProvider.cs | 25 +++++++++++++++++++ Editor/Toolbar/Tools/ToolTimeScale.cs | 16 +++++++----- package.json | 2 +- 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/Editor/Toolbar/Settings/ToolbarSettings.cs b/Editor/Toolbar/Settings/ToolbarSettings.cs index 24977c9..75148c8 100644 --- a/Editor/Toolbar/Settings/ToolbarSettings.cs +++ b/Editor/Toolbar/Settings/ToolbarSettings.cs @@ -8,6 +8,8 @@ namespace Module.NavigationTool.Editor.Toolbar private const string PREF_IS_UI_LAYER_ENABLED = "ToolbarSettings_IsUiLayerEnabled"; private const string PREF_IS_SCENE_ENABLED = "ToolbarSettings_IsSceneEnabled"; private const string PREF_IS_TIME_SCALE_ENABLED = "ToolbarSettings.IsTimeScaleEnabled"; + private const string PREF_TIME_SCALE_MIN = "ToolbarSettings.TimeScaleMin"; + private const string PREF_TIME_SCALE_MAX = "ToolbarSettings.TimeScaleMax"; public static bool IsUiEnabled { @@ -32,5 +34,17 @@ namespace Module.NavigationTool.Editor.Toolbar get => EditorPrefs.GetBool(PREF_IS_TIME_SCALE_ENABLED, false); set => EditorPrefs.SetBool(PREF_IS_TIME_SCALE_ENABLED, value); } + + public static float TimeScaleMinValue + { + get => EditorPrefs.GetFloat(PREF_TIME_SCALE_MIN, 0.0f); + set => EditorPrefs.SetFloat(PREF_TIME_SCALE_MIN, value); + } + + public static float TimeScaleMaxValue + { + get => EditorPrefs.GetFloat(PREF_TIME_SCALE_MAX, 1.0f); + set => EditorPrefs.SetFloat(PREF_TIME_SCALE_MAX, value); + } } } \ No newline at end of file diff --git a/Editor/Toolbar/Settings/ToolbarSettingsProvider.cs b/Editor/Toolbar/Settings/ToolbarSettingsProvider.cs index 3702197..1707a98 100644 --- a/Editor/Toolbar/Settings/ToolbarSettingsProvider.cs +++ b/Editor/Toolbar/Settings/ToolbarSettingsProvider.cs @@ -38,6 +38,31 @@ namespace Module.NavigationTool.Editor.Toolbar EditorGUILayout.Space(); EditorGUILayout.LabelField("Time", EditorStyles.boldLabel); ToolbarSettings.IsTimeScaleEnabled = EditorGUILayout.Toggle("Enable Time Scale slider", ToolbarSettings.IsTimeScaleEnabled); + + GUI.enabled = ToolbarSettings.IsTimeScaleEnabled; + float timeScaleMinValue = EditorGUILayout.FloatField("Min Value", ToolbarSettings.TimeScaleMinValue); + float timeScaleMaxValue = EditorGUILayout.FloatField("Max Value", ToolbarSettings.TimeScaleMaxValue); + + if (!Mathf.Approximately(timeScaleMinValue, ToolbarSettings.TimeScaleMinValue)) + { + if (timeScaleMinValue < 0.0f) + timeScaleMinValue = 0.0f; + + if (timeScaleMinValue > timeScaleMaxValue) + timeScaleMaxValue = timeScaleMinValue; + } + else if (!Mathf.Approximately(timeScaleMaxValue, ToolbarSettings.TimeScaleMaxValue)) + { + if (timeScaleMaxValue < 0.0f) + timeScaleMaxValue = 0.0f; + + if (timeScaleMaxValue < timeScaleMinValue) + timeScaleMinValue = timeScaleMaxValue; + } + + ToolbarSettings.TimeScaleMinValue = timeScaleMinValue; + ToolbarSettings.TimeScaleMaxValue = timeScaleMaxValue; + GUI.enabled = true; } EditorGUILayout.EndVertical(); } diff --git a/Editor/Toolbar/Tools/ToolTimeScale.cs b/Editor/Toolbar/Tools/ToolTimeScale.cs index 1ac37e7..edc953c 100644 --- a/Editor/Toolbar/Tools/ToolTimeScale.cs +++ b/Editor/Toolbar/Tools/ToolTimeScale.cs @@ -15,14 +15,18 @@ namespace Module.NavigationTool.Editor.Toolbar protected override void Draw(Rect rect) { - var r0 = new Rect(rect.x, rect.y, rect.width, rect.height * 0.5f); - EditorGUI.LabelField(r0, "Time scale", EditorStyles.centeredGreyMiniLabel); - - var r1 = new Rect(rect.x + 4.0f, rect.y + rect.height * 0.25f, rect.width - 8.0f, rect.height * 0.5f); float value = Time.timeScale; - float temp = GUI.HorizontalSlider(r1, value, 0.0f, 1.0f); + + var r0 = new Rect(rect.x, rect.y - 2.0f, rect.width, rect.height * 0.5f); + var r1 = new Rect(rect.x + 4.0f, rect.y + 2.0f, rect.width - 8.0f, rect.height * 0.5f); + var r2 = new Rect(rect.x, r1.yMax, rect.width, rect.height * 0.5f); - if (!Mathf.Approximately(value, temp) && value > -0.001f && value < 1.001f) + EditorGUI.LabelField(r0, "Time scale", EditorStyles.centeredGreyMiniLabel); + EditorGUI.LabelField(r2, value.ToString("0.00"), EditorStyles.centeredGreyMiniLabel); + float temp = GUI.HorizontalSlider(r1, value, ToolbarSettings.TimeScaleMinValue, ToolbarSettings.TimeScaleMaxValue); + temp = Mathf.Clamp(temp, ToolbarSettings.TimeScaleMinValue, ToolbarSettings.TimeScaleMaxValue); + + if (!Mathf.Approximately(value, temp)) Time.timeScale = temp; } diff --git a/package.json b/package.json index 0d3e84b..8260ec7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.module.navigationtool", - "version": "1.3.1", + "version": "1.3.2", "displayName": "Module.NavigationTool", "description": "Support for navigation tools, like favorites, history and toolbars", "unity": "2019.2",