Scene: Added "Include Build Scenes", when sorting scenes into sub-menu

This commit is contained in:
Anders Ejlersen 2025-03-31 19:04:13 +02:00
parent 29ab1a90a0
commit 8b927d1997
5 changed files with 70 additions and 6 deletions

View file

@ -2,6 +2,12 @@
All notable changes to this project will be documented in this file. 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 ## [1.11.1] - 2024-11-25
### Added ### Added

View file

@ -9,6 +9,7 @@ namespace Module.NavigationTool.Editor.Toolbar
public string name; public string name;
public ESceneGroupFilterType filterType; public ESceneGroupFilterType filterType;
public ESceneGroupBehaviourType behaviourType; public ESceneGroupBehaviourType behaviourType;
public bool includeBuildScenes;
public string optionalMainScenePath; public string optionalMainScenePath;
public string subMenuPath = "Submenu"; public string subMenuPath = "Submenu";
public List<string> filters = new(); public List<string> filters = new();

View file

@ -44,7 +44,8 @@ namespace Module.NavigationTool.Editor.Toolbar
{ {
name = asset.name, name = asset.name,
shortname = asset.shortname, shortname = asset.shortname,
paths = { asset.path } paths = { asset.path },
inBuildSettings = true
}); });
} }
} }
@ -120,7 +121,11 @@ namespace Module.NavigationTool.Editor.Toolbar
continue; continue;
filteredScenes = FilterToUniques(filteredScenes); filteredScenes = FilterToUniques(filteredScenes);
filteredScenes = FilterAllExcept(filteredScenes, scenes);
if (sceneGroup.includeBuildScenes)
filteredScenes = FilterAllExceptWithBuildScenes(filteredScenes, scenes);
else
filteredScenes = FilterAllExcept(filteredScenes, scenes);
if (filteredScenes.Count != 0) if (filteredScenes.Count != 0)
scenes.Add(new SceneElement{ includeAsSelectable = false }); scenes.Add(new SceneElement{ includeAsSelectable = false });
@ -195,6 +200,38 @@ namespace Module.NavigationTool.Editor.Toolbar
return filtered; return filtered;
} }
private static List<WorkingSetScene> FilterAllExceptWithBuildScenes(List<WorkingSetScene> list, List<SceneElement> except, bool includeGroups = false)
{
var filtered = new List<WorkingSetScene>(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() private void FetchAllLabels()
{ {
labels = new GUIContent[scenes.Count]; labels = new GUIContent[scenes.Count];
@ -395,6 +432,7 @@ namespace Module.NavigationTool.Editor.Toolbar
public string shortname; public string shortname;
public bool includeAsSelectable = true; public bool includeAsSelectable = true;
public bool isGroup; public bool isGroup;
public bool inBuildSettings;
public readonly List<string> paths = new List<string>(); public readonly List<string> paths = new List<string>();
} }

View file

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
@ -51,8 +52,10 @@ namespace Module.NavigationTool.Editor.Toolbar
} }
else if (group.behaviourType == ESceneGroupBehaviourType.SortInSubmenuAsGroup) 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); 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); 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) protected override float OnElementHeight(int index)
{ {
int labelCount = list[index].filters.Count; 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 return base.OnElementHeight(index) * 3f
+ Mathf.Max(0, labelCount - 1) * (EditorGUIUtility.singleLineHeight + 2f) + Mathf.Max(0, labelCount - 1) * (EditorGUIUtility.singleLineHeight + 2f)
+ 104f; + extra;
} }
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "com.module.navigationtool", "name": "com.module.navigationtool",
"version": "1.11.1", "version": "1.11.2",
"displayName": "Module.NavigationTool", "displayName": "Module.NavigationTool",
"description": "Support for navigation tools, like favorites, history and toolbars", "description": "Support for navigation tools, like favorites, history and toolbars",
"unity": "2019.2", "unity": "2019.2",