1.3.2: Added min & max values for time slider and modifiable in settings
This commit is contained in:
parent
21cd509506
commit
40fa4d7151
|
|
@ -8,6 +8,8 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
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";
|
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
|
public static bool IsUiEnabled
|
||||||
{
|
{
|
||||||
|
|
@ -32,5 +34,17 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
get => EditorPrefs.GetBool(PREF_IS_TIME_SCALE_ENABLED, false);
|
get => EditorPrefs.GetBool(PREF_IS_TIME_SCALE_ENABLED, false);
|
||||||
set => EditorPrefs.SetBool(PREF_IS_TIME_SCALE_ENABLED, value);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -38,6 +38,31 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
EditorGUILayout.LabelField("Time", EditorStyles.boldLabel);
|
EditorGUILayout.LabelField("Time", EditorStyles.boldLabel);
|
||||||
ToolbarSettings.IsTimeScaleEnabled = EditorGUILayout.Toggle("Enable Time Scale slider", ToolbarSettings.IsTimeScaleEnabled);
|
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();
|
EditorGUILayout.EndVertical();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,18 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
|
|
||||||
protected override void Draw(Rect rect)
|
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 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;
|
Time.timeScale = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "com.module.navigationtool",
|
"name": "com.module.navigationtool",
|
||||||
"version": "1.3.1",
|
"version": "1.3.2",
|
||||||
"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",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue