Scene Picker: Modified scene groups to contain LoadAsGroup, SortAsGroup and SortInSubmenuAsGroup

### Changed
-  Scene groups to contain three different types of behaviours for grouping:
   - Load As Group: Groups all scenes into a single entry
   - Sort As Group: Sorts all scenes into entries close to each other in the dropdown
   - Sort In Submenu As Group: Sorts all scenes into entries in a submenu

### Removed
- Removed "Scene sorting by Asset label" groups
This commit is contained in:
Anders Ejlersen 2025-03-29 11:12:03 +01:00
parent a7cb8e885b
commit dd80d46ebb
11 changed files with 128 additions and 71 deletions

View file

@ -0,0 +1,9 @@
namespace Module.NavigationTool.Editor.Toolbar
{
public enum ESceneGroupBehaviourType
{
LoadAsGroup,
SortAsGroup,
SortInSubmenuAsGroup
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 71206076ab694b109f3391c4f28bc506
timeCreated: 1743238963

View file

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

View file

@ -24,7 +24,6 @@ namespace Module.NavigationTool.Editor.Toolbar
List<WorkingSetScene> assets = GetWorkingSet();
FetchAllScenesFromBuildSettings(assets);
FetchAllScenesFromLabels(assets, settings.labels);
FetchAllScenesFromSceneGroups(assets, settings.sceneGroups);
FetchAllRemainingScenes(assets);
@ -49,32 +48,9 @@ namespace Module.NavigationTool.Editor.Toolbar
});
}
}
private void FetchAllScenesFromLabels(List<WorkingSetScene> assets, List<string> labels)
{
List<WorkingSetScene> filteredScenes = GetAllWorkingSetScenesWithLabels(assets, labels);
filteredScenes = FilterToUniques(filteredScenes);
filteredScenes = FilterAllExcept(filteredScenes, scenes);
if (filteredScenes.Count != 0)
scenes.Add(new SceneElement{ includeAsSelectable = false });
for (var i = 0; i < filteredScenes.Count; i++)
{
scenes.Add(new SceneElement
{
name = filteredScenes[i].name,
shortname = filteredScenes[i].shortname,
paths = { filteredScenes[i].path }
});
}
}
private void FetchAllScenesFromSceneGroups(List<WorkingSetScene> assets, SceneGroupArray sceneGroups)
{
if (sceneGroups.Count != 0)
scenes.Add(new SceneElement{ includeAsSelectable = false });
for (var i = 0; i < sceneGroups.Count; i++)
{
SceneGroup sceneGroup = sceneGroups[i];
@ -95,28 +71,73 @@ namespace Module.NavigationTool.Editor.Toolbar
name = sceneGroup.name.Replace("/", "\\");
}
if (!string.IsNullOrEmpty(sceneGroup.optionalMainScenePath))
SetWorkingSceneAsFirst(filteredScenes, sceneGroup.optionalMainScenePath);
filteredScenes = FilterToUniques(filteredScenes);
var scene = new SceneElement
if (sceneGroup.behaviourType == ESceneGroupBehaviourType.LoadAsGroup)
{
name = name,
shortname = name,
isGroup = true
};
for (var j = 0; j < filteredScenes.Count; j++)
{
scene.paths.Add(filteredScenes[j].path);
if (sceneGroups.Count != 0)
scenes.Add(new SceneElement{ includeAsSelectable = false });
if (!string.IsNullOrEmpty(sceneGroup.optionalMainScenePath))
SetWorkingSceneAsFirst(filteredScenes, sceneGroup.optionalMainScenePath);
filteredScenes = FilterToUniques(filteredScenes);
var scene = new SceneElement
{
name = name,
shortname = name,
isGroup = true
};
for (var j = 0; j < filteredScenes.Count; j++)
{
scene.paths.Add(filteredScenes[j].path);
}
scene.name += $" ({scene.paths.Count})";
scenes.Add(scene);
}
else if (sceneGroup.behaviourType == ESceneGroupBehaviourType.SortAsGroup)
{
filteredScenes = FilterToUniques(filteredScenes);
filteredScenes = FilterAllExcept(filteredScenes, scenes);
if (filteredScenes.Count != 0)
scenes.Add(new SceneElement{ includeAsSelectable = false });
for (var j = 0; j < filteredScenes.Count; j++)
{
scenes.Add(new SceneElement
{
name = filteredScenes[j].name,
shortname = filteredScenes[j].shortname,
paths = { filteredScenes[j].path }
});
}
}
else if (sceneGroup.behaviourType == ESceneGroupBehaviourType.SortInSubmenuAsGroup)
{
if (string.IsNullOrEmpty(sceneGroup.subMenuPath))
continue;
filteredScenes = FilterToUniques(filteredScenes);
filteredScenes = FilterAllExcept(filteredScenes, scenes);
if (filteredScenes.Count != 0)
scenes.Add(new SceneElement{ includeAsSelectable = false });
for (var j = 0; j < filteredScenes.Count; j++)
{
scenes.Add(new SceneElement
{
name = $"{sceneGroup.subMenuPath}/{filteredScenes[j].name}",
shortname = filteredScenes[j].shortname,
paths = { filteredScenes[j].path }
});
}
}
scene.name += $" ({scene.paths.Count})";
scenes.Add(scene);
}
}
private void FetchAllRemainingScenes(List<WorkingSetScene> assets)
{
List<WorkingSetScene> filteredScenes = FilterAllExcept(assets, scenes);

View file

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
namespace Module.NavigationTool.Editor.Toolbar
{
@ -8,7 +7,6 @@ namespace Module.NavigationTool.Editor.Toolbar
public string Title => "Scene";
public bool IsSettingsDirty { get; private set; }
private StringReorderableListDrawer assetLabelList;
private SceneGroupReorderableListDrawer sceneGroupList;
private ToolbarProjectSettings projectSettings;
@ -19,18 +17,14 @@ namespace Module.NavigationTool.Editor.Toolbar
this.projectSettings = projectSettings;
settings = projectSettings.GetValueAs<Settings>();
assetLabelList = new StringReorderableListDrawer(settings.labels, "Scene sorting by Asset label");
assetLabelList.onChanged += ToolScenePicker.SetAsDirty;
sceneGroupList = new SceneGroupReorderableListDrawer(settings.sceneGroups.groups, "Scene groups");
sceneGroupList.onChanged += ToolScenePicker.SetAsDirty;
}
public void Draw()
{
assetLabelList.DoLayoutList();
sceneGroupList.DoLayoutList();
IsSettingsDirty = assetLabelList.IsDirty || sceneGroupList.IsDirty;
IsSettingsDirty = sceneGroupList.IsDirty;
}
public void SetSettingsValue()
@ -41,7 +35,6 @@ namespace Module.NavigationTool.Editor.Toolbar
[Serializable]
public sealed class Settings
{
public List<string> labels = new();
public SceneGroupArray sceneGroups = new();
}
}

View file

@ -1,7 +1,6 @@
using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
using UTools = UnityEditor.Tools;
namespace Module.NavigationTool.Editor.Toolbar
{