Skip to content

Instantly share code, notes, and snippets.

@shohan4556
Forked from KenneyNL/sceneWindow.cs
Created January 14, 2018 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shohan4556/9f6e4094d8d8652c26c7ac1ab669d849 to your computer and use it in GitHub Desktop.
Save shohan4556/9f6e4094d8d8652c26c7ac1ab669d849 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using System.Collections.Generic;
using System.IO;
// Scene selection
class sceneWindow : EditorWindow {
[MenuItem ("Window/Scenes")]
public static void ShowWindow () {
EditorWindow.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;
}
}
// Selection
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