From 65ca5dd3552d6fb9c2af2ef24591ef0160b15ca6 Mon Sep 17 00:00:00 2001 From: Ejlersen Date: Sat, 15 Jan 2022 11:37:33 +0100 Subject: [PATCH] 1.2.0: added TimeScale to toolbar --- Editor/Toolbar/Settings/ToolbarSettings.cs | 11 ++++-- .../Settings/ToolbarSettingsProvider.cs | 4 +++ Editor/Toolbar/Tools/ToolTimeScale.cs | 34 +++++++++++++++++++ Editor/Toolbar/Tools/ToolTimeScale.cs.meta | 3 ++ README.md | 1 + package.json | 2 +- 6 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 Editor/Toolbar/Tools/ToolTimeScale.cs create mode 100644 Editor/Toolbar/Tools/ToolTimeScale.cs.meta diff --git a/Editor/Toolbar/Settings/ToolbarSettings.cs b/Editor/Toolbar/Settings/ToolbarSettings.cs index 84ed3e9..24977c9 100644 --- a/Editor/Toolbar/Settings/ToolbarSettings.cs +++ b/Editor/Toolbar/Settings/ToolbarSettings.cs @@ -7,16 +7,17 @@ namespace Module.NavigationTool.Editor.Toolbar private const string PREF_IS_UI_ENABLED = "ToolbarSettings_IsUiEnabled"; 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"; public static bool IsUiEnabled { - get => EditorPrefs.GetBool(PREF_IS_UI_ENABLED, true); + get => EditorPrefs.GetBool(PREF_IS_UI_ENABLED, false); set => EditorPrefs.SetBool(PREF_IS_UI_ENABLED, value); } public static bool IsUiLayerEnabled { - get => EditorPrefs.GetBool(PREF_IS_UI_LAYER_ENABLED, true); + get => EditorPrefs.GetBool(PREF_IS_UI_LAYER_ENABLED, false); set => EditorPrefs.SetBool(PREF_IS_UI_LAYER_ENABLED, value); } @@ -25,5 +26,11 @@ namespace Module.NavigationTool.Editor.Toolbar get => EditorPrefs.GetBool(PREF_IS_SCENE_ENABLED, true); set => EditorPrefs.SetBool(PREF_IS_SCENE_ENABLED, value); } + + public static bool IsTimeScaleEnabled + { + get => EditorPrefs.GetBool(PREF_IS_TIME_SCALE_ENABLED, false); + set => EditorPrefs.SetBool(PREF_IS_TIME_SCALE_ENABLED, value); + } } } \ No newline at end of file diff --git a/Editor/Toolbar/Settings/ToolbarSettingsProvider.cs b/Editor/Toolbar/Settings/ToolbarSettingsProvider.cs index 4ac3265..3702197 100644 --- a/Editor/Toolbar/Settings/ToolbarSettingsProvider.cs +++ b/Editor/Toolbar/Settings/ToolbarSettingsProvider.cs @@ -34,6 +34,10 @@ namespace Module.NavigationTool.Editor.Toolbar EditorGUILayout.Space(); EditorGUILayout.LabelField("Scene", EditorStyles.boldLabel); ToolbarSettings.IsSceneEnabled = EditorGUILayout.Toggle("Enable Scene picker", ToolbarSettings.IsSceneEnabled); + + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Time", EditorStyles.boldLabel); + ToolbarSettings.IsTimeScaleEnabled = EditorGUILayout.Toggle("Enable Time Scale slider", ToolbarSettings.IsTimeScaleEnabled); } EditorGUILayout.EndVertical(); } diff --git a/Editor/Toolbar/Tools/ToolTimeScale.cs b/Editor/Toolbar/Tools/ToolTimeScale.cs new file mode 100644 index 0000000..1ac37e7 --- /dev/null +++ b/Editor/Toolbar/Tools/ToolTimeScale.cs @@ -0,0 +1,34 @@ +using JetBrains.Annotations; +using UnityEditor; +using UnityEngine; +using UTools = UnityEditor.Tools; + +namespace Module.NavigationTool.Editor.Toolbar +{ + [UsedImplicitly] + internal sealed class ToolTimeScale : AbstractToolbarDrawer + { + public override bool Visible => ToolbarSettings.IsTimeScaleEnabled; + public override bool Enabled => true; + public override EToolbarPlacement Placement => EToolbarPlacement.Left; + public override int Priority => (int)EToolbarPriority.Low; + + 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); + + if (!Mathf.Approximately(value, temp) && value > -0.001f && value < 1.001f) + Time.timeScale = temp; + } + + public override float CalculateWidth() + { + return 100.0f; + } + } +} \ No newline at end of file diff --git a/Editor/Toolbar/Tools/ToolTimeScale.cs.meta b/Editor/Toolbar/Tools/ToolTimeScale.cs.meta new file mode 100644 index 0000000..832387e --- /dev/null +++ b/Editor/Toolbar/Tools/ToolTimeScale.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 757111b1895840149b30b5945b0c8ad1 +timeCreated: 1641415892 \ No newline at end of file diff --git a/README.md b/README.md index bde9241..c083003 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Three tools are available from start: * UI Layer: Toggle the UI layer on/off * UI Canvas: Select and center the camera on any Canvases in the scene * Scene: Load any scene in the project easily by using the dropdown +* Time Scale: Adjust the time scale from [0;1] from a slider ### Customization diff --git a/package.json b/package.json index 8f05763..7b82a18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.module.navigationtool", - "version": "1.1.0", + "version": "1.2.0", "displayName": "Module.NavigationTool", "description": "Support for navigation tools, like favorites, history and toolbars", "unity": "2019.2",