system
1
‘How can I create an EditorWindow that let’s me Swap Scenes?’
Several of my projects have a lot of scenes I would like to make it easier to navigate between them. I am trying to make an EditorWindow that has a list of buttons that swap scenes for me. I do not like having to dig through my project folder trying to find a specific scene. (I am also planning to have a ‘recent’ section at the top, which will include the last 3-5 scenes you loaded; assuming I can get it to work…)
I can make an editor window, I can make buttons & do all of the required things including load scenes. However I currently do now know how to retrieve a list of available scenes. And I don’t mean the scenes that are in the build settings, I want a list of ALL of the current scenes.
I tried
Object[] currentScenes = AssetDatabase.LoadAllAssetsAtPath("Assets/Scenes");
But this didn’t return any results.
Again I need a list of all the current scenes, or all of the .unity files in other words.
Thanks
To search your scenes in your project’s folder, use this :
private static void RefreshScenes()
{
ScenesFileInfo = (new DirectoryInfo(Application.dataPath)).GetFiles("*.unity", SearchOption.AllDirectories);
}
void OnProjectChange()
{
RefreshScenes();
}
This will get you the fileInfo of your scene files. And then, to display rouy scenes
for (int i = 0; i < ScenesFileInfo.Length; i++)
{
GUI.Box(tmp, "", i % 2 == 0 ? "OL EntryBackEven" : "OL EntryBackOdd");
GUI.Label(new Rect(tmp.x + tmp.height, tmp.y, tmp.width - tmp.height, tmp.height), ScenesFileInfo*.Name, "OL Label");*
tmp.y += tmp.height;
}
Before loading your scene, save if needed :
EditorApplication.SaveCurrentSceneIfUserWantsTo();
EditorApplication.OpenScene(“path to your scene”);