Created
January 4, 2019 10:52
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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