From 91c9504910d13f2e1b94402e6d2dfec4d8f59893 Mon Sep 17 00:00:00 2001 From: Anders Ejlersen Date: Mon, 14 Feb 2022 20:57:58 +0100 Subject: [PATCH] 1.5.0: Added interface and utility class for adding settings to toolbar settings provider --- Editor/Toolbar/Settings/IToolbarSettings.cs | 9 +++ .../Toolbar/Settings/IToolbarSettings.cs.meta | 3 + Editor/Toolbar/Settings/ToolbarSettings.cs | 64 ----------------- .../Toolbar/Settings/ToolbarSettings.cs.meta | 3 - .../Settings/ToolbarSettingsProvider.cs | 70 +++++++------------ Editor/Toolbar/ToolbarDrawer.cs | 24 ++++--- Editor/Toolbar/Tools/Settings.meta | 3 + .../Tools/Settings/ToolbarBuildSettings.cs | 29 ++++++++ .../Settings/ToolbarBuildSettings.cs.meta | 3 + .../Settings/ToolbarScenePickerSettings.cs | 22 ++++++ .../ToolbarScenePickerSettings.cs.meta | 3 + .../Tools/Settings/ToolbarTimeSettings.cs | 62 ++++++++++++++++ .../Settings/ToolbarTimeSettings.cs.meta | 3 + .../Tools/Settings/ToolbarUiSettings.cs | 30 ++++++++ .../Tools/Settings/ToolbarUiSettings.cs.meta | 3 + Editor/Toolbar/Tools/ToolBuild.cs | 6 +- Editor/Toolbar/Tools/ToolBuildTargetPicker.cs | 2 +- Editor/Toolbar/Tools/ToolScenePicker.cs | 2 +- Editor/Toolbar/Tools/ToolTimeScale.cs | 6 +- Editor/Toolbar/Tools/ToolUICanvasPicker.cs | 2 +- Editor/Toolbar/Tools/ToolUILayerToggle.cs | 2 +- .../Utilities/ToolbarSettingsUtility.cs | 43 ++++++++++++ .../Utilities/ToolbarSettingsUtility.cs.meta | 3 + Editor/Toolbar/Utilities/ToolbarUtility.cs | 6 +- package.json | 2 +- 25 files changed, 272 insertions(+), 133 deletions(-) create mode 100644 Editor/Toolbar/Settings/IToolbarSettings.cs create mode 100644 Editor/Toolbar/Settings/IToolbarSettings.cs.meta delete mode 100644 Editor/Toolbar/Settings/ToolbarSettings.cs delete mode 100644 Editor/Toolbar/Settings/ToolbarSettings.cs.meta create mode 100644 Editor/Toolbar/Tools/Settings.meta create mode 100644 Editor/Toolbar/Tools/Settings/ToolbarBuildSettings.cs create mode 100644 Editor/Toolbar/Tools/Settings/ToolbarBuildSettings.cs.meta create mode 100644 Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs create mode 100644 Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs.meta create mode 100644 Editor/Toolbar/Tools/Settings/ToolbarTimeSettings.cs create mode 100644 Editor/Toolbar/Tools/Settings/ToolbarTimeSettings.cs.meta create mode 100644 Editor/Toolbar/Tools/Settings/ToolbarUiSettings.cs create mode 100644 Editor/Toolbar/Tools/Settings/ToolbarUiSettings.cs.meta create mode 100644 Editor/Toolbar/Utilities/ToolbarSettingsUtility.cs create mode 100644 Editor/Toolbar/Utilities/ToolbarSettingsUtility.cs.meta diff --git a/Editor/Toolbar/Settings/IToolbarSettings.cs b/Editor/Toolbar/Settings/IToolbarSettings.cs new file mode 100644 index 0000000..5e6c240 --- /dev/null +++ b/Editor/Toolbar/Settings/IToolbarSettings.cs @@ -0,0 +1,9 @@ +namespace Module.NavigationTool.Editor.Toolbar +{ + public interface IToolbarSettings + { + string Title { get; } + + void Draw(); + } +} \ No newline at end of file diff --git a/Editor/Toolbar/Settings/IToolbarSettings.cs.meta b/Editor/Toolbar/Settings/IToolbarSettings.cs.meta new file mode 100644 index 0000000..adad6be --- /dev/null +++ b/Editor/Toolbar/Settings/IToolbarSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 66bccfd6abba42ba9d07f0d746d6179d +timeCreated: 1644864241 \ No newline at end of file diff --git a/Editor/Toolbar/Settings/ToolbarSettings.cs b/Editor/Toolbar/Settings/ToolbarSettings.cs deleted file mode 100644 index 80645f1..0000000 --- a/Editor/Toolbar/Settings/ToolbarSettings.cs +++ /dev/null @@ -1,64 +0,0 @@ -using UnityEditor; - -namespace Module.NavigationTool.Editor.Toolbar -{ - internal static class ToolbarSettings - { - 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_BUILD_ENABLED = "ToolbarSettings.IsBuildEnabled"; - private const string PREF_IS_BUILD_AND_RUN_ENABLED = "ToolbarSettings.IsBuildAndRunEnabled"; - 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 - { - 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, false); - set => EditorPrefs.SetBool(PREF_IS_UI_LAYER_ENABLED, value); - } - - public static bool IsSceneEnabled - { - get => EditorPrefs.GetBool(PREF_IS_SCENE_ENABLED, true); - set => EditorPrefs.SetBool(PREF_IS_SCENE_ENABLED, value); - } - - public static bool IsBuildEnabled - { - get => EditorPrefs.GetBool(PREF_IS_BUILD_ENABLED, false); - set => EditorPrefs.SetBool(PREF_IS_BUILD_ENABLED, value); - } - - public static bool IsBuildAndRunEnabled - { - get => EditorPrefs.GetBool(PREF_IS_BUILD_AND_RUN_ENABLED, true); - set => EditorPrefs.SetBool(PREF_IS_BUILD_AND_RUN_ENABLED, value); - } - - public static bool IsTimeScaleEnabled - { - get => EditorPrefs.GetBool(PREF_IS_TIME_SCALE_ENABLED, false); - 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); - } - } -} \ No newline at end of file diff --git a/Editor/Toolbar/Settings/ToolbarSettings.cs.meta b/Editor/Toolbar/Settings/ToolbarSettings.cs.meta deleted file mode 100644 index 2a2843a..0000000 --- a/Editor/Toolbar/Settings/ToolbarSettings.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: ee57c1a04c9448e585e7e524886bdeda -timeCreated: 1639924440 \ No newline at end of file diff --git a/Editor/Toolbar/Settings/ToolbarSettingsProvider.cs b/Editor/Toolbar/Settings/ToolbarSettingsProvider.cs index ec6e6ae..a23dc38 100644 --- a/Editor/Toolbar/Settings/ToolbarSettingsProvider.cs +++ b/Editor/Toolbar/Settings/ToolbarSettingsProvider.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using UnityEditor; using UnityEngine; @@ -6,67 +7,50 @@ namespace Module.NavigationTool.Editor.Toolbar internal static class ToolbarSettingsProvider { private static Styles STYLES; + private static IToolbarSettings[] SETTINGS; [SettingsProvider] public static SettingsProvider GetProvider() { + Initialize(); + var keywords = new List { "Toolbar" }; + + for (var i = 0; i < SETTINGS.Length; i++) + { + keywords.Add(SETTINGS[i].Title); + } + return new SettingsProvider("Module/Toolbar", SettingsScope.User) { label = "Toolbar", - keywords = new[] { "Scene", "UI", "Toolbar" }, + keywords = keywords.ToArray(), guiHandler = OnGui }; } - private static void OnGui(string searchContext) + private static void Initialize() { if (STYLES == null) STYLES = new Styles(); - - STYLES.Initialize((GUI.skin)); - + if (SETTINGS == null) + SETTINGS = ToolbarSettingsUtility.GetAllSettings(); + } + + private static void OnGui(string searchContext) + { + Initialize(); + STYLES.Initialize(GUI.skin); + EditorGUILayout.BeginVertical(STYLES.settingsGroup); { - EditorGUILayout.LabelField("UI", EditorStyles.boldLabel); - ToolbarSettings.IsUiEnabled = EditorGUILayout.Toggle("Enable Canvas picker", ToolbarSettings.IsUiEnabled); - ToolbarSettings.IsUiLayerEnabled = EditorGUILayout.Toggle("Enable Layer toggle", ToolbarSettings.IsUiLayerEnabled); - - EditorGUILayout.Space(); - EditorGUILayout.LabelField("Scene", EditorStyles.boldLabel); - ToolbarSettings.IsSceneEnabled = EditorGUILayout.Toggle("Enable Scene picker", ToolbarSettings.IsSceneEnabled); - - EditorGUILayout.Space(); - EditorGUILayout.LabelField("Build Target", EditorStyles.boldLabel); - ToolbarSettings.IsBuildEnabled = EditorGUILayout.Toggle("Enable Build Target picker", ToolbarSettings.IsBuildEnabled); - - EditorGUILayout.Space(); - EditorGUILayout.LabelField("Time", EditorStyles.boldLabel); - 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)) + for (var i = 0; i < SETTINGS.Length; i++) { - if (timeScaleMinValue < 0.0f) - timeScaleMinValue = 0.0f; - - if (timeScaleMinValue > timeScaleMaxValue) - timeScaleMaxValue = timeScaleMinValue; + IToolbarSettings settings = SETTINGS[i]; + + EditorGUILayout.LabelField(settings.Title, EditorStyles.boldLabel); + settings.Draw(); + EditorGUILayout.Space(); } - 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(); } diff --git a/Editor/Toolbar/ToolbarDrawer.cs b/Editor/Toolbar/ToolbarDrawer.cs index 122480b..0ac99e5 100644 --- a/Editor/Toolbar/ToolbarDrawer.cs +++ b/Editor/Toolbar/ToolbarDrawer.cs @@ -52,6 +52,8 @@ namespace Module.NavigationTool.Editor.Toolbar private static void OnUpdateElements(VisualElement leftAlign, VisualElement rightAlign) { const float HEIGHT = 22.0f; + const float ADD_CATEGORY = 2.0f; + var added = false; for (int i = DRAWERS.Length - 1; i >= 0; i--) @@ -61,18 +63,22 @@ namespace Module.NavigationTool.Editor.Toolbar if (drawer.Visible && !valid) { - var rect = new Rect(2.0f, 0.0f, drawer.CalculateWidth(), HEIGHT); + var rect = new Rect(ADD_CATEGORY, 0.0f, drawer.CalculateWidth(), HEIGHT); drawer.Setup(rect); - - var container = new ToolbarIMGUIContainer(drawer.OnGUI, drawer.Priority); - container.style.width = rect.width + 4.0f; - DICT_MAPPING.Add(drawer, container); - added = true; + var container = new ToolbarIMGUIContainer(drawer.OnGUI, drawer.Priority); + + VisualElement parent; if (drawer.Placement == EToolbarPlacement.Left) - leftAlign.Add(container); + parent = leftAlign; else - rightAlign.Add(container); + parent = rightAlign; + + container.style.width = rect.width + ADD_CATEGORY * 2.0f; + DICT_MAPPING.Add(drawer, container); + + added = true; + parent.Add(container); } else if (!drawer.Visible && valid) { @@ -115,7 +121,7 @@ namespace Module.NavigationTool.Editor.Toolbar return -1; if (c1 == null) return 1; - + return c0.Priority.CompareTo(c1.Priority); } #else diff --git a/Editor/Toolbar/Tools/Settings.meta b/Editor/Toolbar/Tools/Settings.meta new file mode 100644 index 0000000..598d1b2 --- /dev/null +++ b/Editor/Toolbar/Tools/Settings.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a630457a27194c8b8e93a7d8b2a8ae27 +timeCreated: 1644864264 \ No newline at end of file diff --git a/Editor/Toolbar/Tools/Settings/ToolbarBuildSettings.cs b/Editor/Toolbar/Tools/Settings/ToolbarBuildSettings.cs new file mode 100644 index 0000000..b5c5901 --- /dev/null +++ b/Editor/Toolbar/Tools/Settings/ToolbarBuildSettings.cs @@ -0,0 +1,29 @@ +using UnityEditor; + +namespace Module.NavigationTool.Editor.Toolbar +{ + internal sealed class ToolbarBuildSettings : IToolbarSettings + { + public string Title => "Build"; + + private const string PREF_IS_BUILD_ENABLED = "ToolbarSettings.IsBuildEnabled"; + private const string PREF_IS_BUILD_AND_RUN_ENABLED = "ToolbarSettings.IsBuildAndRunEnabled"; + + public static bool IsBuildEnabled + { + get => EditorPrefs.GetBool(PREF_IS_BUILD_ENABLED, false); + set => EditorPrefs.SetBool(PREF_IS_BUILD_ENABLED, value); + } + + public static bool IsBuildAndRunEnabled + { + get => EditorPrefs.GetBool(PREF_IS_BUILD_AND_RUN_ENABLED, true); + set => EditorPrefs.SetBool(PREF_IS_BUILD_AND_RUN_ENABLED, value); + } + + public void Draw() + { + IsBuildEnabled = EditorGUILayout.Toggle("Enable Build Target picker", IsBuildEnabled); + } + } +} \ No newline at end of file diff --git a/Editor/Toolbar/Tools/Settings/ToolbarBuildSettings.cs.meta b/Editor/Toolbar/Tools/Settings/ToolbarBuildSettings.cs.meta new file mode 100644 index 0000000..1d1c078 --- /dev/null +++ b/Editor/Toolbar/Tools/Settings/ToolbarBuildSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 05811b28871541ec868123c6176c987f +timeCreated: 1644864282 \ No newline at end of file diff --git a/Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs b/Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs new file mode 100644 index 0000000..a4dd75d --- /dev/null +++ b/Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs @@ -0,0 +1,22 @@ +using UnityEditor; + +namespace Module.NavigationTool.Editor.Toolbar +{ + internal sealed class ToolbarScenePickerSettings : IToolbarSettings + { + public string Title => "Scene"; + + private const string PREF_IS_SCENE_ENABLED = "ToolbarSettings_IsSceneEnabled"; + + public static bool IsSceneEnabled + { + get => EditorPrefs.GetBool(PREF_IS_SCENE_ENABLED, true); + set => EditorPrefs.SetBool(PREF_IS_SCENE_ENABLED, value); + } + + public void Draw() + { + IsSceneEnabled = EditorGUILayout.Toggle("Enable Scene picker", IsSceneEnabled); + } + } +} \ No newline at end of file diff --git a/Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs.meta b/Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs.meta new file mode 100644 index 0000000..31ba50f --- /dev/null +++ b/Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 40d094d8314a485988bb647a72b78fb4 +timeCreated: 1644864987 \ No newline at end of file diff --git a/Editor/Toolbar/Tools/Settings/ToolbarTimeSettings.cs b/Editor/Toolbar/Tools/Settings/ToolbarTimeSettings.cs new file mode 100644 index 0000000..a0c9ab5 --- /dev/null +++ b/Editor/Toolbar/Tools/Settings/ToolbarTimeSettings.cs @@ -0,0 +1,62 @@ +using UnityEditor; +using UnityEngine; + +namespace Module.NavigationTool.Editor.Toolbar +{ + internal sealed class ToolbarTimeSettings : IToolbarSettings + { + public string Title => "Time"; + + 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 IsTimeScaleEnabled + { + get => EditorPrefs.GetBool(PREF_IS_TIME_SCALE_ENABLED, false); + 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); + } + + public void Draw() + { + IsTimeScaleEnabled = EditorGUILayout.Toggle("Enable Time Scale slider", IsTimeScaleEnabled); + + GUI.enabled = IsTimeScaleEnabled; + float timeScaleMinValue = EditorGUILayout.FloatField("Min Value", TimeScaleMinValue); + float timeScaleMaxValue = EditorGUILayout.FloatField("Max Value", TimeScaleMaxValue); + + if (!Mathf.Approximately(timeScaleMinValue, TimeScaleMinValue)) + { + if (timeScaleMinValue < 0.0f) + timeScaleMinValue = 0.0f; + + if (timeScaleMinValue > timeScaleMaxValue) + timeScaleMaxValue = timeScaleMinValue; + } + else if (!Mathf.Approximately(timeScaleMaxValue, TimeScaleMaxValue)) + { + if (timeScaleMaxValue < 0.0f) + timeScaleMaxValue = 0.0f; + + if (timeScaleMaxValue < timeScaleMinValue) + timeScaleMinValue = timeScaleMaxValue; + } + + TimeScaleMinValue = timeScaleMinValue; + TimeScaleMaxValue = timeScaleMaxValue; + GUI.enabled = true; + } + } +} \ No newline at end of file diff --git a/Editor/Toolbar/Tools/Settings/ToolbarTimeSettings.cs.meta b/Editor/Toolbar/Tools/Settings/ToolbarTimeSettings.cs.meta new file mode 100644 index 0000000..a3352da --- /dev/null +++ b/Editor/Toolbar/Tools/Settings/ToolbarTimeSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4ff04b8c4eb645eba58747d2399f8825 +timeCreated: 1644865203 \ No newline at end of file diff --git a/Editor/Toolbar/Tools/Settings/ToolbarUiSettings.cs b/Editor/Toolbar/Tools/Settings/ToolbarUiSettings.cs new file mode 100644 index 0000000..79e726d --- /dev/null +++ b/Editor/Toolbar/Tools/Settings/ToolbarUiSettings.cs @@ -0,0 +1,30 @@ +using UnityEditor; + +namespace Module.NavigationTool.Editor.Toolbar +{ + internal sealed class ToolbarUiSettings : IToolbarSettings + { + public string Title => "UI"; + + private const string PREF_IS_UI_ENABLED = "ToolbarSettings_IsUiEnabled"; + private const string PREF_IS_UI_LAYER_ENABLED = "ToolbarSettings_IsUiLayerEnabled"; + + public static bool IsUiEnabled + { + 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, false); + set => EditorPrefs.SetBool(PREF_IS_UI_LAYER_ENABLED, value); + } + + public void Draw() + { + IsUiEnabled = EditorGUILayout.Toggle("Enable Canvas picker", IsUiEnabled); + IsUiLayerEnabled = EditorGUILayout.Toggle("Enable Layer toggle", IsUiLayerEnabled); + } + } +} \ No newline at end of file diff --git a/Editor/Toolbar/Tools/Settings/ToolbarUiSettings.cs.meta b/Editor/Toolbar/Tools/Settings/ToolbarUiSettings.cs.meta new file mode 100644 index 0000000..036c563 --- /dev/null +++ b/Editor/Toolbar/Tools/Settings/ToolbarUiSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ce06d92a6c084745bb04f8468a3b2802 +timeCreated: 1644865309 \ No newline at end of file diff --git a/Editor/Toolbar/Tools/ToolBuild.cs b/Editor/Toolbar/Tools/ToolBuild.cs index 5a6c66d..6abc13a 100644 --- a/Editor/Toolbar/Tools/ToolBuild.cs +++ b/Editor/Toolbar/Tools/ToolBuild.cs @@ -8,7 +8,7 @@ namespace Module.NavigationTool.Editor.Toolbar [UsedImplicitly] internal sealed class ToolBuild : AbstractToolbarDrawer { - public override bool Visible => ToolbarSettings.IsBuildEnabled; + public override bool Visible => ToolbarBuildSettings.IsBuildEnabled; public override bool Enabled => !Application.isPlaying; public override EToolbarPlacement Placement => EToolbarPlacement.Left; public override int Priority => (int)EToolbarPriority.Low; @@ -50,7 +50,7 @@ namespace Module.NavigationTool.Editor.Toolbar var rect0 = new Rect(rect.x, rect.y, rect.width - 16.0f, rect.height); var rect1 = new Rect(rect0.xMax, rect.y, 16.0f, rect.height); - int currentSelected = ToolbarSettings.IsBuildAndRunEnabled ? 1 : 0; + int currentSelected = ToolbarBuildSettings.IsBuildAndRunEnabled ? 1 : 0; if (GUI.Button(rect0, BUTTON_LIST[currentSelected], styles.buttonNoPadding)) { @@ -65,7 +65,7 @@ namespace Module.NavigationTool.Editor.Toolbar EditorUtility.DisplayCustomMenu(rect, CONTENT_LIST, currentSelected, (userData, options, selected) => { if (selected != -1) - ToolbarSettings.IsBuildAndRunEnabled = selected == 1; + ToolbarBuildSettings.IsBuildAndRunEnabled = selected == 1; }, null); } } diff --git a/Editor/Toolbar/Tools/ToolBuildTargetPicker.cs b/Editor/Toolbar/Tools/ToolBuildTargetPicker.cs index fe60ebd..645514d 100644 --- a/Editor/Toolbar/Tools/ToolBuildTargetPicker.cs +++ b/Editor/Toolbar/Tools/ToolBuildTargetPicker.cs @@ -11,7 +11,7 @@ namespace Module.NavigationTool.Editor.Toolbar [UsedImplicitly] internal sealed class ToolBuildTargetPicker : AbstractToolbarDrawer { - public override bool Visible => ToolbarSettings.IsBuildEnabled; + public override bool Visible => ToolbarBuildSettings.IsBuildEnabled; public override bool Enabled => !Application.isPlaying; public override EToolbarPlacement Placement => EToolbarPlacement.Left; public override int Priority => (int)EToolbarPriority.Low; diff --git a/Editor/Toolbar/Tools/ToolScenePicker.cs b/Editor/Toolbar/Tools/ToolScenePicker.cs index 36a03e4..6c617bf 100644 --- a/Editor/Toolbar/Tools/ToolScenePicker.cs +++ b/Editor/Toolbar/Tools/ToolScenePicker.cs @@ -12,7 +12,7 @@ namespace Module.NavigationTool.Editor.Toolbar [UsedImplicitly] internal sealed class ToolScenePicker : AbstractToolbarDrawer { - public override bool Visible => ToolbarSettings.IsSceneEnabled; + public override bool Visible => ToolbarScenePickerSettings.IsSceneEnabled; public override bool Enabled => !EditorApplication.isPlaying && !EditorApplication.isPlayingOrWillChangePlaymode; public override EToolbarPlacement Placement => EToolbarPlacement.Right; public override int Priority => (int)EToolbarPriority.Medium; diff --git a/Editor/Toolbar/Tools/ToolTimeScale.cs b/Editor/Toolbar/Tools/ToolTimeScale.cs index 1705ae1..64ab607 100644 --- a/Editor/Toolbar/Tools/ToolTimeScale.cs +++ b/Editor/Toolbar/Tools/ToolTimeScale.cs @@ -8,7 +8,7 @@ namespace Module.NavigationTool.Editor.Toolbar [UsedImplicitly] internal sealed class ToolTimeScale : AbstractToolbarDrawer { - public override bool Visible => ToolbarSettings.IsTimeScaleEnabled; + public override bool Visible => ToolbarTimeSettings.IsTimeScaleEnabled; public override bool Enabled => true; public override EToolbarPlacement Placement => EToolbarPlacement.Left; public override int Priority => (int)EToolbarPriority.Low; @@ -23,8 +23,8 @@ namespace Module.NavigationTool.Editor.Toolbar 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); + float temp = GUI.HorizontalSlider(r1, value, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue); + temp = Mathf.Clamp(temp, ToolbarTimeSettings.TimeScaleMinValue, ToolbarTimeSettings.TimeScaleMaxValue); if (Mathf.Abs(temp - 1.0f) < 0.02f) temp = 1.0f; diff --git a/Editor/Toolbar/Tools/ToolUICanvasPicker.cs b/Editor/Toolbar/Tools/ToolUICanvasPicker.cs index b46bf34..bb1a179 100644 --- a/Editor/Toolbar/Tools/ToolUICanvasPicker.cs +++ b/Editor/Toolbar/Tools/ToolUICanvasPicker.cs @@ -16,7 +16,7 @@ namespace Module.NavigationTool.Editor.Toolbar [UsedImplicitly] internal sealed class ToolUICanvasPicker : AbstractToolbarDrawer { - public override bool Visible => ToolbarSettings.IsUiEnabled; + public override bool Visible => ToolbarUiSettings.IsUiEnabled; public override bool Enabled => (UTools.visibleLayers & (1 << LayerMask.NameToLayer("UI"))) != 0; public override EToolbarPlacement Placement => EToolbarPlacement.Left; public override int Priority => (int)EToolbarPriority.Medium; diff --git a/Editor/Toolbar/Tools/ToolUILayerToggle.cs b/Editor/Toolbar/Tools/ToolUILayerToggle.cs index 67432f8..29f3737 100644 --- a/Editor/Toolbar/Tools/ToolUILayerToggle.cs +++ b/Editor/Toolbar/Tools/ToolUILayerToggle.cs @@ -8,7 +8,7 @@ namespace Module.NavigationTool.Editor.Toolbar [UsedImplicitly] internal sealed class ToolUILayerToggle : AbstractToolbarDrawer { - public override bool Visible => ToolbarSettings.IsUiLayerEnabled; + public override bool Visible => ToolbarUiSettings.IsUiLayerEnabled; public override bool Enabled => true; public override EToolbarPlacement Placement => EToolbarPlacement.Left; public override int Priority => (int)EToolbarPriority.Medium - 1; diff --git a/Editor/Toolbar/Utilities/ToolbarSettingsUtility.cs b/Editor/Toolbar/Utilities/ToolbarSettingsUtility.cs new file mode 100644 index 0000000..ceb96e7 --- /dev/null +++ b/Editor/Toolbar/Utilities/ToolbarSettingsUtility.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Runtime.Serialization; + +namespace Module.NavigationTool.Editor.Toolbar +{ + internal static class ToolbarSettingsUtility + { + public static IToolbarSettings[] GetAllSettings() + { + var list = new List(8); + + try + { + Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); + Type iType = typeof(IToolbarSettings); + + for (var i = 0; i < assemblies.Length; i++) + { + Assembly assembly = assemblies[i]; + Type[] types = assembly.GetTypes(); + + for (var j = 0; j < types.Length; j++) + { + Type type = types[j]; + + if (!type.IsInterface && !type.IsAbstract && iType.IsAssignableFrom(type)) + list.Add((IToolbarSettings)FormatterServices.GetUninitializedObject(type)); + } + } + + list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal)); + } + catch (Exception) + { + // Fail silently + } + + return list.ToArray(); + } + } +} \ No newline at end of file diff --git a/Editor/Toolbar/Utilities/ToolbarSettingsUtility.cs.meta b/Editor/Toolbar/Utilities/ToolbarSettingsUtility.cs.meta new file mode 100644 index 0000000..e6d8e1a --- /dev/null +++ b/Editor/Toolbar/Utilities/ToolbarSettingsUtility.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c951cc6b880347bd9e710b8fee3788c5 +timeCreated: 1644864048 \ No newline at end of file diff --git a/Editor/Toolbar/Utilities/ToolbarUtility.cs b/Editor/Toolbar/Utilities/ToolbarUtility.cs index df6b0da..bdc08ba 100644 --- a/Editor/Toolbar/Utilities/ToolbarUtility.cs +++ b/Editor/Toolbar/Utilities/ToolbarUtility.cs @@ -164,9 +164,7 @@ namespace Module.NavigationTool.Editor.Toolbar { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); Type iType = typeof(AbstractToolbarDrawer); - - - + for (var i = 0; i < assemblies.Length; i++) { Assembly assembly = assemblies[i]; @@ -180,6 +178,8 @@ namespace Module.NavigationTool.Editor.Toolbar list.Add((AbstractToolbarDrawer)FormatterServices.GetUninitializedObject(type)); } } + + list.Sort((t0, t1) => t0.Priority.CompareTo(t1.Priority)); } catch (Exception) { diff --git a/package.json b/package.json index 32a351f..c0dcc2c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.module.navigationtool", - "version": "1.4.1", + "version": "1.5.0", "displayName": "Module.NavigationTool", "description": "Support for navigation tools, like favorites, history and toolbars", "unity": "2019.2",