Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEditor;
using UnityEditor.SceneManagement;
using System.IO;
using UnityEditorInternal;
using UnityEngine;
[InitializeOnLoad]
public class AutoChangeLayout
{
static string sceneName = null;
static AutoChangeLayout ()
{
EditorApplication.update += Update;
}
static void Update ()
{
var activeScene = EditorSceneManager.GetActiveScene();
if (! EditorApplication.isPlaying && sceneName != activeScene.name)
{
var oldSceneName = sceneName;
sceneName = activeScene.name;
if (oldSceneName == null)
{
return;
}
string layoutsPath = Path.Combine(InternalEditorUtility.unityPreferencesFolder, "Layouts");
string layoutName;
if (sceneName == "Level Select")
{
layoutName = "editor-and-hierarchy";
}
else
{
layoutName = "My custom layout";
}
string filePath = Path.Combine(layoutsPath, layoutName + ".wlt");
EditorUtility.LoadWindowLayout(filePath);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment