0.6.2: Added all scenes to scene picker

This commit is contained in:
Anders Ejlersen 2021-04-27 15:14:12 +02:00
parent 2a875eda93
commit 17c55cd03c
2 changed files with 32 additions and 6 deletions

View file

@ -29,15 +29,36 @@ namespace Game.NavigationTool.Editor.Tools
EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
var listNames = new List<string>(scenes.Length);
var listPaths = new List<string>(scenes.Length);
for (var i = 0; i < scenes.Length; i++)
{
if (string.IsNullOrEmpty(scenes[i].path))
continue;
listNames.Add(Path.GetFileNameWithoutExtension(scenes[i].path));
listNames.Add($"{Path.GetFileNameWithoutExtension(scenes[i].path)} (Build Settings)");
listPaths.Add(scenes[i].path);
}
string[] guids = AssetDatabase.FindAssets("t:scene");
int startIndex = listNames.Count;
for (var i = 0; i < guids.Length; i++)
{
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
var scene = AssetDatabase.LoadAssetAtPath<SceneAsset>(path);
if (scene == null || listPaths.Contains(path))
continue;
listNames.Add(path.Substring(7, path.Length - 13).Replace('/', '\\'));
listPaths.Add(path);
}
if (startIndex < listNames.Count)
{
listNames.Insert(startIndex, string.Empty);
listPaths.Insert(startIndex, string.Empty);
}
OPTIONS = listNames.ToArray();
PATHS = listPaths.ToArray();
@ -56,14 +77,19 @@ namespace Game.NavigationTool.Editor.Tools
{
Initialize();
int temp = EditorGUI.Popup(rect, SELECTED_INDEX, OPTIONS, styles.popup);
if (temp != -1 && temp != SELECTED_INDEX && OPTIONS.Length != 0)
if (temp > -1 && temp != SELECTED_INDEX && OPTIONS.Length != 0)
{
string path = PATHS[temp];
if (string.IsNullOrEmpty(path))
return;
SELECTED_INDEX = temp;
EditorSceneManager.OpenScene(PATHS[SELECTED_INDEX], OpenSceneMode.Single);
}
}
public float CalculateWidth()
{
return 100.0f;

View file

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