Skip to content

Instantly share code, notes, and snippets.

@col000r
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save col000r/9763447 to your computer and use it in GitHub Desktop.
Save col000r/9763447 to your computer and use it in GitHub Desktop.
Unity3D: Automatic Layout-switching whenever you enter/exit play-mode!
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
class PlayModeSwitch : EditorWindow {
static bool lastValue = false;
static PlayModeSwitch () {
if(!EditorPrefs.GetBool("AutoSwitchToggle", false)) return; //Check if feature is enabled
EditorApplication.update += Update;
lastValue = Application.isPlaying;
}
static void Update () {
if(lastValue != Application.isPlaying) {
if(Application.isPlaying == true) {
Debug.Log ("SWITCHING LAYOUT! **********************************************");
EditorApplication.ExecuteMenuItem("Window/Layouts/PLAY"); //ENTER YOUR PLAY LAYOUT NAME HERE or create a layout named PLAY
} else {
Debug.Log ("SWITCHING LAYOUT! **********************************************");
EditorApplication.ExecuteMenuItem("Window/Layouts/WORK"); //ENTER YOUR WORK LAYOUT NAME HERE or create a layout named WORK
}
lastValue = Application.isPlaying;
}
}
[MenuItem("Window/Layouts/Toggle AutoSwitch %F12", false, -999)] //Add to the Layouts menu
static void ToggleSwitch() {
bool b = EditorPrefs.GetBool("AutoSwitchToggle", false);
EditorPrefs.SetBool("AutoSwitchToggle", !b);
Debug.Log ("Automatic Layout Switching is now " + (!b ? "on" : "off") + "!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment