diff --git a/README.md b/README.md index be6eb4a..6321fda 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ An editor window, where the history of all selected assets are shown. An asset i ## Toolbar -Toolbars to the left and right of the play-buttons. Anything can be added, as long as it is supported by IMGUI. +Toolbars to the left and right of the play-buttons by using the `MainToolbarElement`-attribute. ### Default tools @@ -25,7 +25,6 @@ Several tools are available from start: * Build: Select build target and build * Player Prefs: Delete all PlayerPrefs data * Scene: Load any scene in the project easily by using the dropdown -* Target Frame Rate Scale: Adjust target frame rate from [10;144] from a slider * Time Scale: Adjust the time scale from [0;1] from a slider * UI Canvas: Select and center the camera on any Canvases in the scene * UI Layer: Toggle the UI layer on/off @@ -35,35 +34,40 @@ Several tools are available from start: ### Customization -You can create your own toolbar extensions by extending `AbstractToolbarDrawer`. +You can create your own toolbar extensions by using the property attribute `MainToolbarElement`. ``` -internal sealed class MyCustomTool : AbstractToolbarDrawer +[Preserve] +[MainToolbarElement("Toolbar/Time Scale", ussName = "", defaultDockIndex = 0, defaultDockPosition = MainToolbarDockPosition.Middle, menuPriority = 500)] +public static MainToolbarElement Draw() { - public override bool Visible => true; - public override bool Enabled => true; - public override EToolbarPlacement Placement => EToolbarPlacement.Left; - public override int Priority => (int)EToolbarPriority.Medium; + 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); +} - protected override void Draw(Rect rect) - { - // Use IMGUI methods for drawing - } +private static void OnTimeScaleValueChanged(float value) +{ + value = Mathf.Clamp(value, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue); - public override float CalculateWidth() - { - // Default width for toolbar buttons is 30 - return 30.0f; - } + if (Mathf.Abs(value - 1.0f) < 0.02f) + value = 1.0f; + + if (!Mathf.Approximately(Time.timeScale, value)) + Time.timeScale = value; } ``` -The four properties help define draw and enable state: +A list of multiple controls can be done by changing: -* `Visible`: If it is visible in the toolbar -* `Enabled`: If it is enabled in the toolbar (`GUI.enabled`) -* `Placement`: If it is placed to the left or right of the play-buttons -* `Priority`: Sort order/priority, when drawing the tool +``` +public static MainToolbarElement Draw() +``` + +to + +``` +public static IEnumerable Draw() +``` ### Customization - Settings @@ -71,29 +75,35 @@ The four properties help define draw and enable state: To add enable/disable settings or more to Preferences -> Toolbar, you can implement `IToolbarSettings`. ``` -internal sealed class ToolbarUiSettings : IToolbarSettings +internal sealed class ToolbarFooSettings : IToolbarSettings { - public string Title => "UI"; + public string Title => "Foo"; - private const string PREF_IS_UI_ENABLED = "ToolbarSettings_IsUiEnabled"; - private const string PREF_IS_UI_LAYER_ENABLED = "ToolbarSettings_IsUiLayerEnabled"; + private const string PREF_MIN_VALUE = "ToolbarSettings_MinValue"; + private const string PREF_MAX_VALUE = "ToolbarSettings_MaxValue"; - public static bool IsUiEnabled + public static float MinValue { - get => EditorPrefs.GetBool(PREF_IS_UI_ENABLED, false); - set => EditorPrefs.SetBool(PREF_IS_UI_ENABLED, value); + get => EditorPrefs.GetFloat(PREF_IS_UI_ENABLED, false); + set => EditorPrefs.SetFloat(PREF_IS_UI_ENABLED, value); } - public static bool IsUiLayerEnabled + public static float MaxValue { - get => EditorPrefs.GetBool(PREF_IS_UI_LAYER_ENABLED, false); - set => EditorPrefs.SetBool(PREF_IS_UI_LAYER_ENABLED, value); + get => EditorPrefs.GetFloat(PREF_IS_UI_LAYER_ENABLED, false); + set => EditorPrefs.SetFloat(PREF_IS_UI_LAYER_ENABLED, value); } public void Draw() { - IsUiEnabled = EditorGUILayout.Toggle("Enable Canvas picker", IsUiEnabled); - IsUiLayerEnabled = EditorGUILayout.Toggle("Enable Layer toggle", IsUiLayerEnabled); + MinValue = EditorGUILayout.FloatField("Min Value", TimeScaleMinValue); + MaxValue = EditorGUILayout.FloatField("Max Value", TimeScaleMaxValue); } } +``` + +If you need to refresh a control, due to changes in settings. Then invoke: + +``` +MainToolbar.Refresh("Toolbar/Time Scale"); ``` \ No newline at end of file