1.7.0: Added option to sort scenes by asset labels
This commit is contained in:
parent
d9e62f6589
commit
cceef7bb7e
9 changed files with 136 additions and 21 deletions
|
|
@ -57,18 +57,17 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
|
||||
private static void InitializeRemainingScenes(List<string> listNames, List<string> listPaths)
|
||||
{
|
||||
List<string> sortByAssetLabels = ToolbarScenePickerSettings.SceneAssetLabels;
|
||||
var assetLabelToScenes = new SceneSortElement[sortByAssetLabels.Count + 1];
|
||||
string[] guids = AssetDatabase.FindAssets("t:scene");
|
||||
int startIndex = listNames.Count;
|
||||
|
||||
|
||||
for (var i = 0; i < guids.Length; i++)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
|
||||
|
||||
if (listPaths.Contains(path))
|
||||
if (listPaths.Contains(path) || !path.StartsWith("Assets"))
|
||||
continue;
|
||||
if (!path.StartsWith("Assets"))
|
||||
continue;
|
||||
|
||||
|
||||
var scene = AssetDatabase.LoadAssetAtPath<SceneAsset>(path);
|
||||
|
||||
if (scene == null)
|
||||
|
|
@ -76,16 +75,40 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
|
||||
string sceneName = path.Substring(7, path.Length - 13)
|
||||
.Replace('/', '\\');
|
||||
|
||||
listNames.Add(sceneName);
|
||||
listPaths.Add(path);
|
||||
|
||||
string[] assetLabels = AssetDatabase.GetLabels(scene);
|
||||
int index = -1;
|
||||
|
||||
for (var j = 0; j < assetLabels.Length; j++)
|
||||
{
|
||||
index = sortByAssetLabels.IndexOf(assetLabels[j]);
|
||||
|
||||
if (index != -1)
|
||||
break;
|
||||
}
|
||||
|
||||
if (index == -1)
|
||||
index = sortByAssetLabels.Count;
|
||||
if (assetLabelToScenes[index] == null)
|
||||
assetLabelToScenes[index] = new SceneSortElement();
|
||||
|
||||
assetLabelToScenes[index].names.Add(sceneName);
|
||||
assetLabelToScenes[index].paths.Add(path);
|
||||
}
|
||||
|
||||
if (startIndex >= listNames.Count)
|
||||
return;
|
||||
|
||||
listNames.Insert(startIndex, string.Empty);
|
||||
listPaths.Insert(startIndex, string.Empty);
|
||||
for (var i = 0; i < assetLabelToScenes.Length; i++)
|
||||
{
|
||||
SceneSortElement e = assetLabelToScenes[i];
|
||||
|
||||
if (e == null)
|
||||
continue;
|
||||
|
||||
listNames.Add(string.Empty);
|
||||
listPaths.Add(string.Empty);
|
||||
|
||||
listNames.AddRange(e.names);
|
||||
listPaths.AddRange(e.paths);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
|
|
@ -125,5 +148,11 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
{
|
||||
IS_DIRTY = true;
|
||||
}
|
||||
|
||||
private sealed class SceneSortElement
|
||||
{
|
||||
public readonly List<string> names = new List<string>();
|
||||
public readonly List<string> paths = new List<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue