Last active
August 29, 2015 13:57
-
-
Save col000r/9763447 to your computer and use it in GitHub Desktop.
Unity3D: Automatic Layout-switching whenever you enter/exit play-mode!
This file contains hidden or 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 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