1.2.0: added TimeScale to toolbar

This commit is contained in:
Anders Ejlersen 2022-01-15 11:37:33 +01:00
parent 9802f8aaa3
commit 65ca5dd355
6 changed files with 52 additions and 3 deletions

View file

@ -7,16 +7,17 @@ namespace Module.NavigationTool.Editor.Toolbar
private const string PREF_IS_UI_ENABLED = "ToolbarSettings_IsUiEnabled"; private const string PREF_IS_UI_ENABLED = "ToolbarSettings_IsUiEnabled";
private const string PREF_IS_UI_LAYER_ENABLED = "ToolbarSettings_IsUiLayerEnabled"; private const string PREF_IS_UI_LAYER_ENABLED = "ToolbarSettings_IsUiLayerEnabled";
private const string PREF_IS_SCENE_ENABLED = "ToolbarSettings_IsSceneEnabled"; private const string PREF_IS_SCENE_ENABLED = "ToolbarSettings_IsSceneEnabled";
private const string PREF_IS_TIME_SCALE_ENABLED = "ToolbarSettings.IsTimeScaleEnabled";
public static bool IsUiEnabled 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); set => EditorPrefs.SetBool(PREF_IS_UI_ENABLED, value);
} }
public static bool IsUiLayerEnabled 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); 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); get => EditorPrefs.GetBool(PREF_IS_SCENE_ENABLED, true);
set => EditorPrefs.SetBool(PREF_IS_SCENE_ENABLED, value); 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);
}
} }
} }

View file

@ -34,6 +34,10 @@ namespace Module.NavigationTool.Editor.Toolbar
EditorGUILayout.Space(); EditorGUILayout.Space();
EditorGUILayout.LabelField("Scene", EditorStyles.boldLabel); EditorGUILayout.LabelField("Scene", EditorStyles.boldLabel);
ToolbarSettings.IsSceneEnabled = EditorGUILayout.Toggle("Enable Scene picker", ToolbarSettings.IsSceneEnabled); 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(); EditorGUILayout.EndVertical();
} }

View file

@ -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;
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 757111b1895840149b30b5945b0c8ad1
timeCreated: 1641415892

View file

@ -25,6 +25,7 @@ Three tools are available from start:
* UI Layer: Toggle the UI layer on/off * UI Layer: Toggle the UI layer on/off
* UI Canvas: Select and center the camera on any Canvases in the scene * 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 * 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 ### Customization

View file

@ -1,6 +1,6 @@
{ {
"name": "com.module.navigationtool", "name": "com.module.navigationtool",
"version": "1.1.0", "version": "1.2.0",
"displayName": "Module.NavigationTool", "displayName": "Module.NavigationTool",
"description": "Support for navigation tools, like favorites, history and toolbars", "description": "Support for navigation tools, like favorites, history and toolbars",
"unity": "2019.2", "unity": "2019.2",