Scene Picker: Fixed issue, where it would display deleted or unsaved scenes and selectable or no label entries
This commit is contained in:
parent
959f012d80
commit
5e0634e069
|
|
@ -48,10 +48,14 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
for (var i = 0; i < SceneManager.sceneCount; i++)
|
||||
{
|
||||
Scene scene = SceneManager.GetSceneAt(i);
|
||||
|
||||
if (string.IsNullOrEmpty(scene.path))
|
||||
continue;
|
||||
|
||||
int index = listPaths.IndexOf(scene.path);
|
||||
|
||||
if (index != -1)
|
||||
SELECTED_INDICES.Add(listPaths.IndexOf(scene.path));
|
||||
SELECTED_INDICES.Add(index);
|
||||
}
|
||||
|
||||
SCENE_NAMES = listNames.ToArray();
|
||||
|
|
@ -66,14 +70,19 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
{
|
||||
EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
|
||||
|
||||
for (var i = 0; i < scenes.Length; i++)
|
||||
for (int i = 0, added = 0; i < scenes.Length; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(scenes[i].path))
|
||||
string path = scenes[i].path;
|
||||
|
||||
if (string.IsNullOrEmpty(path))
|
||||
continue;
|
||||
if (AssetDatabase.LoadAssetAtPath<SceneAsset>(path) == null)
|
||||
continue;
|
||||
|
||||
listNames.Add(Path.GetFileNameWithoutExtension(scenes[i].path));
|
||||
listShortNames.Add(listNames[i]);
|
||||
listPaths.Add(scenes[i].path);
|
||||
listNames.Add(Path.GetFileNameWithoutExtension(path));
|
||||
listShortNames.Add(listNames[added]);
|
||||
listPaths.Add(path);
|
||||
added++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -219,6 +228,8 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
}
|
||||
|
||||
private static void SelectScene(int index)
|
||||
{
|
||||
try
|
||||
{
|
||||
string path = SCENE_PATHS[index];
|
||||
Scene scene = SceneManager.GetSceneByPath(path);
|
||||
|
|
@ -246,11 +257,18 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
|
||||
RefreshSceneLabel();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RefreshSceneLabel()
|
||||
{
|
||||
STRING_BUILDER.Clear();
|
||||
|
||||
if (SELECTED_INDICES.Count != 0)
|
||||
{
|
||||
for (var i = 0; i < SELECTED_INDICES.Count; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
|
|
@ -258,6 +276,11 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
|
||||
STRING_BUILDER.Append(SCENE_SHORT_NAMES[SELECTED_INDICES[i]]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
STRING_BUILDER.Append("Unsaved scene(s)");
|
||||
}
|
||||
|
||||
SCENE_LABEL = STRING_BUILDER.ToString();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue