From 8b927d199768b1540f54fb57e5ce96183bdb4ce8 Mon Sep 17 00:00:00 2001 From: Anders Ejlersen Date: Mon, 31 Mar 2025 19:04:13 +0200 Subject: [PATCH] Scene: Added "Include Build Scenes", when sorting scenes into sub-menu --- CHANGELOG.md | 6 +++ .../Tools/ScenePickerObjects/SceneGroup.cs | 1 + .../ScenePickerObjects/ScenePickerList.cs | 42 ++++++++++++++++++- .../SceneGroupReorderableListDrawer.cs | 25 +++++++++-- package.json | 2 +- 5 files changed, 70 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07134ae..28b3326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## [1.11.2] - 2024-11-26 + +### Added +- Added "Include Build Scenes", when sorting scenes into sub-menu + + ## [1.11.1] - 2024-11-25 ### Added diff --git a/Editor/Toolbar/Tools/ScenePickerObjects/SceneGroup.cs b/Editor/Toolbar/Tools/ScenePickerObjects/SceneGroup.cs index 0bac14c..fd9f18a 100644 --- a/Editor/Toolbar/Tools/ScenePickerObjects/SceneGroup.cs +++ b/Editor/Toolbar/Tools/ScenePickerObjects/SceneGroup.cs @@ -9,6 +9,7 @@ namespace Module.NavigationTool.Editor.Toolbar public string name; public ESceneGroupFilterType filterType; public ESceneGroupBehaviourType behaviourType; + public bool includeBuildScenes; public string optionalMainScenePath; public string subMenuPath = "Submenu"; public List filters = new(); diff --git a/Editor/Toolbar/Tools/ScenePickerObjects/ScenePickerList.cs b/Editor/Toolbar/Tools/ScenePickerObjects/ScenePickerList.cs index 5131874..f7ee3e7 100644 --- a/Editor/Toolbar/Tools/ScenePickerObjects/ScenePickerList.cs +++ b/Editor/Toolbar/Tools/ScenePickerObjects/ScenePickerList.cs @@ -44,7 +44,8 @@ namespace Module.NavigationTool.Editor.Toolbar { name = asset.name, shortname = asset.shortname, - paths = { asset.path } + paths = { asset.path }, + inBuildSettings = true }); } } @@ -120,7 +121,11 @@ namespace Module.NavigationTool.Editor.Toolbar continue; filteredScenes = FilterToUniques(filteredScenes); - filteredScenes = FilterAllExcept(filteredScenes, scenes); + + if (sceneGroup.includeBuildScenes) + filteredScenes = FilterAllExceptWithBuildScenes(filteredScenes, scenes); + else + filteredScenes = FilterAllExcept(filteredScenes, scenes); if (filteredScenes.Count != 0) scenes.Add(new SceneElement{ includeAsSelectable = false }); @@ -195,6 +200,38 @@ namespace Module.NavigationTool.Editor.Toolbar return filtered; } + private static List FilterAllExceptWithBuildScenes(List list, List except, bool includeGroups = false) + { + var filtered = new List(list.Count); + + for (var i = 0; i < list.Count; i++) + { + var contains = false; + + for (var j = except.Count - 1; j >= 0; j--) + { + if (except[j].isGroup && !includeGroups) + continue; + if (!except[j].paths.Contains(list[i].path)) + continue; + + if (except[j].inBuildSettings) + { + except.RemoveAt(j); + break; + } + + contains = true; + break; + } + + if (!contains) + filtered.Add(list[i]); + } + + return filtered; + } + private void FetchAllLabels() { labels = new GUIContent[scenes.Count]; @@ -395,6 +432,7 @@ namespace Module.NavigationTool.Editor.Toolbar public string shortname; public bool includeAsSelectable = true; public bool isGroup; + public bool inBuildSettings; public readonly List paths = new List(); } diff --git a/Editor/Toolbar/Utilities/ReordableList/SceneGroupReorderableListDrawer.cs b/Editor/Toolbar/Utilities/ReordableList/SceneGroupReorderableListDrawer.cs index 8b8a1ca..34551d2 100644 --- a/Editor/Toolbar/Utilities/ReordableList/SceneGroupReorderableListDrawer.cs +++ b/Editor/Toolbar/Utilities/ReordableList/SceneGroupReorderableListDrawer.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using UnityEditor; using UnityEngine; @@ -51,8 +52,10 @@ namespace Module.NavigationTool.Editor.Toolbar } else if (group.behaviourType == ESceneGroupBehaviourType.SortInSubmenuAsGroup) { - var rectOptional = new Rect(rect.x, rectType.yMax + 2f, rect.width, EditorGUIUtility.singleLineHeight); + var rectIncludeBuildScenes = new Rect(rect.x, rectType.yMax + 2f, rect.width, EditorGUIUtility.singleLineHeight); + var rectOptional = new Rect(rect.x, rectIncludeBuildScenes.yMax + 2f, rect.width, EditorGUIUtility.singleLineHeight); rectLabels = new Rect(rect.x, rectOptional.yMax + 2f, rect.width, rect.height - (rectName.y - rectOptional.yMax) - 4f); + group.includeBuildScenes = EditorGUI.Toggle(rectIncludeBuildScenes, "Include Build Scenes", group.includeBuildScenes); group.subMenuPath = EditorGUI.TextField(rectOptional, "Sub-menu Path", group.subMenuPath); } @@ -85,10 +88,26 @@ namespace Module.NavigationTool.Editor.Toolbar protected override float OnElementHeight(int index) { int labelCount = list[index].filters.Count; + float extra; + + switch (list[index].behaviourType) + { + case ESceneGroupBehaviourType.LoadAsGroup: + extra = 98f; + break; + case ESceneGroupBehaviourType.SortAsGroup: + extra = 80f; + break; + case ESceneGroupBehaviourType.SortInSubmenuAsGroup: + extra = 120f; + break; + default: + throw new ArgumentOutOfRangeException(); + } return base.OnElementHeight(index) * 3f + Mathf.Max(0, labelCount - 1) * (EditorGUIUtility.singleLineHeight + 2f) - + 104f; + + extra; } } } \ No newline at end of file diff --git a/package.json b/package.json index 6f93fd1..ac7f4d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.module.navigationtool", - "version": "1.11.1", + "version": "1.11.2", "displayName": "Module.NavigationTool", "description": "Support for navigation tools, like favorites, history and toolbars", "unity": "2019.2",