Skip to content

Instantly share code, notes, and snippets.

@Noxalus
Created January 4, 2019 10:52
Show Gist options
  • Save Noxalus/ea24fbe39fd0ceba8b7864c58277e240 to your computer and use it in GitHub Desktop.
Save Noxalus/ea24fbe39fd0ceba8b7864c58277e240 to your computer and use it in GitHub Desktop.
Add a entry in the Unity menu Window/Scenes that shows a window to easily load scene files.
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
class SceneWindow : EditorWindow
{
[MenuItem("Window/Scenes")]
public static void ShowWindow()
{
GetWindow(typeof(SceneWindow), false, "Scenes");
}
int selected; int changedSelected;
List<string> scenes = new List<string>();
void OnGUI()
{
EditorGUILayout.Space();
scenes.Clear();
string[] dropOptions = new string[EditorBuildSettings.scenes.Length];
for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
{
EditorBuildSettingsScene scene = EditorBuildSettings.scenes[i];
string sceneName = Path.GetFileNameWithoutExtension(scene.path);
scenes.Add(sceneName);
dropOptions[i] = scenes[i];
if (scene.path == EditorSceneManager.GetActiveScene().path)
{
selected = changedSelected = i;
}
}
changedSelected = EditorGUILayout.Popup(selected, dropOptions);
if (selected != changedSelected)
{
selected = changedSelected;
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
EditorSceneManager.OpenScene(EditorBuildSettings.scenes[changedSelected].path);
}
EditorGUILayout.Space();
EditorGUILayout.LabelField("Scenes", EditorStyles.boldLabel);
for (int i = 0; i < scenes.Count; i++)
{
if (GUILayout.Button(scenes[i], GUILayout.Height(20)))
{
selected = changedSelected = i;
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
EditorSceneManager.OpenScene(EditorBuildSettings.scenes[i].path);
}
dropOptions[i] = scenes[i];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment