This file contains 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 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