Navigation tools upgraded to use the new MainToolbarElement API
This commit is contained in:
parent
708b99f763
commit
3e1602162c
52 changed files with 837 additions and 66 deletions
|
|
@ -0,0 +1,30 @@
|
|||
#if UNITY_6000_3_OR_NEWER
|
||||
using UnityEditor.Toolbars;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Scripting;
|
||||
|
||||
namespace Module.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
internal static class MainToolbarTimeScaleElement
|
||||
{
|
||||
[Preserve]
|
||||
[MainToolbarElement("Toolbar/Time Scale", ussName = "", defaultDockIndex = 0, defaultDockPosition = MainToolbarDockPosition.Middle, menuPriority = 500)]
|
||||
public static MainToolbarElement Draw()
|
||||
{
|
||||
var content = new MainToolbarContent("Time:", "Adjust Time.timeScale from [min;max] and snaps when value is approximately 1.0");
|
||||
return new MainToolbarSlider(content, Time.timeScale, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue, OnTimeScaleValueChanged);
|
||||
}
|
||||
|
||||
private static void OnTimeScaleValueChanged(float value)
|
||||
{
|
||||
value = Mathf.Clamp(value, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue);
|
||||
|
||||
if (Mathf.Abs(value - 1.0f) < 0.02f)
|
||||
value = 1.0f;
|
||||
|
||||
if (!Mathf.Approximately(Time.timeScale, value))
|
||||
Time.timeScale = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue