From de2745d68a8c23c1f188579724416332b8642b92 Mon Sep 17 00:00:00 2001 From: Anders Ejlersen Date: Tue, 14 Mar 2023 19:59:02 +0100 Subject: [PATCH] 1.8.2: Changed icon on scene loading toggle and added a create new scene button --- CHANGELOG.md | 11 +++- Editor/Toolbar/AbstractToolbarDrawer.cs | 2 +- .../Tools/Settings/ToolbarProjectSettings.cs | 26 ++++++++ .../Settings/ToolbarProjectSettings.cs.meta | 3 + .../Settings/ToolbarScenePickerSettings.cs | 2 +- Editor/Toolbar/Tools/ToolProjectSave.cs | 32 ++++++++++ Editor/Toolbar/Tools/ToolProjectSave.cs.meta | 3 + Editor/Toolbar/Tools/ToolScenePicker.cs | 62 +++++++++++++++---- Editor/Toolbar/Utilities/Styles.cs | 10 ++- package.json | 2 +- 10 files changed, 134 insertions(+), 19 deletions(-) create mode 100644 Editor/Toolbar/Tools/Settings/ToolbarProjectSettings.cs create mode 100644 Editor/Toolbar/Tools/Settings/ToolbarProjectSettings.cs.meta create mode 100644 Editor/Toolbar/Tools/ToolProjectSave.cs create mode 100644 Editor/Toolbar/Tools/ToolProjectSave.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index c4525a0..59d25e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,16 @@ # Change Log All notable changes to this project will be documented in this file. -## [1.8.0] - 2022-12-07 +## [1.8.2] - 2023-03-14 + +### Added +- Create new scene next to scene picker + +### Changed +- Icon on additive and single scene toggle changed to be single or multiple "window" icon + + +## [1.8.1] - 2022-12-07 ### Changed - Updated README.md to include all default tools diff --git a/Editor/Toolbar/AbstractToolbarDrawer.cs b/Editor/Toolbar/AbstractToolbarDrawer.cs index 58b9256..3f5aefc 100644 --- a/Editor/Toolbar/AbstractToolbarDrawer.cs +++ b/Editor/Toolbar/AbstractToolbarDrawer.cs @@ -8,7 +8,7 @@ namespace Module.NavigationTool.Editor.Toolbar public abstract bool Enabled { get; } public abstract EToolbarPlacement Placement { get; } public abstract int Priority { get; } - + private Rect rect; protected Styles styles; diff --git a/Editor/Toolbar/Tools/Settings/ToolbarProjectSettings.cs b/Editor/Toolbar/Tools/Settings/ToolbarProjectSettings.cs new file mode 100644 index 0000000..29db65b --- /dev/null +++ b/Editor/Toolbar/Tools/Settings/ToolbarProjectSettings.cs @@ -0,0 +1,26 @@ +using UnityEditor; + +namespace Module.NavigationTool.Editor.Toolbar +{ + internal sealed class ToolbarProjectSettings : IToolbarSettings + { + public string Title => "Project"; + + private const string PREF_PROJECT_SAVE_ENABLED = "ToolbarSettings.IsProjectSaveEnabled"; + + public static bool IsProjectSaveEnabled + { + get => EditorPrefs.GetBool(PREF_PROJECT_SAVE_ENABLED, false); + set => EditorPrefs.SetBool(PREF_PROJECT_SAVE_ENABLED, value); + } + + public void Initialize() + { + } + + public void Draw() + { + IsProjectSaveEnabled = EditorGUILayout.Toggle("Enable Save button", IsProjectSaveEnabled); + } + } +} \ No newline at end of file diff --git a/Editor/Toolbar/Tools/Settings/ToolbarProjectSettings.cs.meta b/Editor/Toolbar/Tools/Settings/ToolbarProjectSettings.cs.meta new file mode 100644 index 0000000..46779b1 --- /dev/null +++ b/Editor/Toolbar/Tools/Settings/ToolbarProjectSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0442ccbddf87428b85f2d98cfa033ca5 +timeCreated: 1670955254 \ No newline at end of file diff --git a/Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs b/Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs index 30271e8..867b740 100644 --- a/Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs +++ b/Editor/Toolbar/Tools/Settings/ToolbarScenePickerSettings.cs @@ -32,7 +32,7 @@ namespace Module.NavigationTool.Editor.Toolbar get => EditorPrefs.GetBool(PREF_SCENE_PICKER_LOAD_SET_AS_ADDITIVE_KEY, false); set => EditorPrefs.SetBool(PREF_SCENE_PICKER_LOAD_SET_AS_ADDITIVE_KEY, value); } - + private ReorderableList assetLabelList; private List assetLabels; diff --git a/Editor/Toolbar/Tools/ToolProjectSave.cs b/Editor/Toolbar/Tools/ToolProjectSave.cs new file mode 100644 index 0000000..6258352 --- /dev/null +++ b/Editor/Toolbar/Tools/ToolProjectSave.cs @@ -0,0 +1,32 @@ +using JetBrains.Annotations; +using UnityEditor; +using UnityEngine; +using UTools = UnityEditor.Tools; + +namespace Module.NavigationTool.Editor.Toolbar +{ + [UsedImplicitly] + internal sealed class ToolProjectSave : AbstractToolbarDrawer + { + public override bool Visible => ToolbarProjectSettings.IsProjectSaveEnabled; + public override bool Enabled => true; + public override EToolbarPlacement Placement => EToolbarPlacement.Right; + public override int Priority => (int)EToolbarPriority.Low; + + private static readonly GUIContent LABEL = new GUIContent(string.Empty, "Deletes all PlayerPrefs entries"); + + protected override void Draw(Rect rect) + { + bool isButtonPressed = GUI.Button(rect, styles.iconProject, styles.button); + GUI.Label(rect, LABEL, styles.labelCenter); + + if (isButtonPressed) + AssetDatabase.SaveAssets(); + } + + public override float CalculateWidth() + { + return 24.0f; + } + } +} \ No newline at end of file diff --git a/Editor/Toolbar/Tools/ToolProjectSave.cs.meta b/Editor/Toolbar/Tools/ToolProjectSave.cs.meta new file mode 100644 index 0000000..61090ea --- /dev/null +++ b/Editor/Toolbar/Tools/ToolProjectSave.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 97a541d20e644506b1fe20e85e561642 +timeCreated: 1670955217 \ No newline at end of file diff --git a/Editor/Toolbar/Tools/ToolScenePicker.cs b/Editor/Toolbar/Tools/ToolScenePicker.cs index 7a8cb07..e1ed296 100644 --- a/Editor/Toolbar/Tools/ToolScenePicker.cs +++ b/Editor/Toolbar/Tools/ToolScenePicker.cs @@ -24,8 +24,10 @@ namespace Module.NavigationTool.Editor.Toolbar private static string[] SCENE_NAMES = new string[0]; private static string[] SCENE_SHORT_NAMES = new string[0]; private static string[] SCENE_PATHS = new string[0]; - private static readonly GUIContent LABEL_ADDITIVE = new GUIContent(string.Empty, "Toggles between Single and Additive scene loading"); - + private static readonly GUIContent LABEL_SCENE_ADDITIVE = new GUIContent(string.Empty, "Additive scene loading (toogle to Single)"); + private static readonly GUIContent LABEL_SCENE_SINGLE = new GUIContent(string.Empty, "Single scene loading (toggle to Additive)"); + private static readonly GUIContent LABEL_SCENE_CREATE = new GUIContent(string.Empty, "Create a new scene"); + private const float BUTTON_WIDTH = 24.0f; private static bool IS_DIRTY = true; @@ -142,19 +144,55 @@ namespace Module.NavigationTool.Editor.Toolbar protected override void Draw(Rect rect) { Initialize(); - var rect0 = new Rect(rect.x, rect.y, rect.width - 24.0f, rect.height); - var rect1 = new Rect(rect0.xMax, rect.y, 24.0f, rect.height); + + var rect0 = new Rect(rect.x, rect.y, rect.width - BUTTON_WIDTH * 2.0f, rect.height); + var rect1 = new Rect(rect0.xMax, rect.y, BUTTON_WIDTH, rect.height); + var rect2 = new Rect(rect1.xMax, rect.y, BUTTON_WIDTH, rect.height); + DrawSceneDropDown(rect0); + DrawSceneLoadToggle(rect1); + DrawSceneAddButton(rect2); + } - if (GUI.Button(rect0, SCENE_LABEL, styles.popup)) - ShowDropDown(rect0); + private void DrawSceneDropDown(Rect rect) + { + if (GUI.Button(rect, SCENE_LABEL, styles.popup)) + ShowDropDown(rect); + } + private void DrawSceneLoadToggle(Rect rect) + { bool isScenePickerSetAsAdditive = ToolbarScenePickerSettings.IsScenePickerSetAsAdditive; - bool temp = EditorGUI.Toggle(rect1, isScenePickerSetAsAdditive, styles.button); - GUI.Label(rect1, temp ? styles.iconPlusSmall : styles.iconPlusTiny, styles.labelCenter); - GUI.Label(rect1, LABEL_ADDITIVE, styles.labelCenter); + bool tempIsAdditive = EditorGUI.Toggle(rect, isScenePickerSetAsAdditive, styles.button); - if (temp != isScenePickerSetAsAdditive) - ToolbarScenePickerSettings.IsScenePickerSetAsAdditive = temp; + if (tempIsAdditive) + { + GUI.Label(rect, styles.iconSceneAdditive, styles.labelCenter); + GUI.Label(rect, LABEL_SCENE_ADDITIVE, styles.labelCenter); + } + else + { + GUI.Label(rect, styles.iconSceneSingle, styles.labelCenter); + GUI.Label(rect, LABEL_SCENE_SINGLE, styles.labelCenter); + } + + if (tempIsAdditive != isScenePickerSetAsAdditive) + ToolbarScenePickerSettings.IsScenePickerSetAsAdditive = tempIsAdditive; + } + + private void DrawSceneAddButton(Rect rect) + { + if (GUI.Button(rect, styles.iconPlusSmall, styles.button)) + { + if (!EditorUtility.DisplayDialog("Create new scene", "Are you sure that you want to create a new scene?", "Yes", "No")) + return; + + Scene scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive); + + if (EditorUtility.DisplayDialog("Create new scene", "Save scene to disk?", "Yes", "No")) + EditorSceneManager.SaveScene(scene); + } + + GUI.Label(rect, LABEL_SCENE_CREATE, styles.labelCenter); } private static void ShowDropDown(Rect rect) @@ -216,7 +254,7 @@ namespace Module.NavigationTool.Editor.Toolbar public override float CalculateWidth() { - return 124.0f; + return 100.0f + BUTTON_WIDTH * 2.0f; } public static void SetAsDirty() diff --git a/Editor/Toolbar/Utilities/Styles.cs b/Editor/Toolbar/Utilities/Styles.cs index 262d31d..e9af760 100644 --- a/Editor/Toolbar/Utilities/Styles.cs +++ b/Editor/Toolbar/Utilities/Styles.cs @@ -15,8 +15,10 @@ namespace Module.NavigationTool.Editor.Toolbar public GUIStyle centeredMiniLabel; public GUIContent iconPlusSmall; - public GUIContent iconPlusTiny; + public GUIContent iconSceneAdditive; + public GUIContent iconSceneSingle; public GUIContent iconDisconnect; + public GUIContent iconProject; private GUISkin skin; @@ -30,7 +32,7 @@ namespace Module.NavigationTool.Editor.Toolbar button = new GUIStyle(skin.FindStyle("toolbarbutton")); slider = new GUIStyle(skin.FindStyle("ToolbarSlider")); label = new GUIStyle(skin.FindStyle("ToolbarLabel")); - + if (EditorGUIUtility.isProSkin) { centeredMiniLabel = EditorStyles.centeredGreyMiniLabel; @@ -57,8 +59,10 @@ namespace Module.NavigationTool.Editor.Toolbar }; iconPlusSmall = EditorGUIUtility.IconContent("d_CreateAddNew"); - iconPlusTiny = EditorGUIUtility.IconContent("Toolbar Plus"); + iconSceneAdditive = EditorGUIUtility.IconContent("d_winbtn_win_restore_h"); + iconSceneSingle = EditorGUIUtility.IconContent("d_winbtn_win_max_h"); iconDisconnect = EditorGUIUtility.IconContent("d_CacheServerDisconnected"); + iconProject = EditorGUIUtility.IconContent("Project"); } } } \ No newline at end of file diff --git a/package.json b/package.json index 1ca01a5..06adf6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.module.navigationtool", - "version": "1.8.1", + "version": "1.8.2", "displayName": "Module.NavigationTool", "description": "Support for navigation tools, like favorites, history and toolbars", "unity": "2019.2",