Created
May 26, 2017 06:11
-
-
Save LordNed/a6baacd73dab56e40814d26ee288b902 to your computer and use it in GitHub Desktop.
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 UnityEngine; | |
[InitializeOnLoad] | |
public class EditorEvents | |
{ | |
// InitializeOnLoad causes this to get called when the editor starts up | |
static EditorEvents() | |
{ | |
EditorApplication.update += Update; | |
} | |
static void Update() | |
{ | |
// If compiling starts while in play mode, it's often really useful to just quit now before the errors start spinning up! | |
if (EditorApplication.isPlaying && EditorApplication.isCompiling && EditorPrefs.GetBool(EditorPlaymodeStop.CompileStopsPlayPrefsKey, true)) | |
EditorApplication.isPlaying = false; | |
} | |
} | |
public class EditorPlaymodeStop : EditorWindow | |
{ | |
public const string CompileStopsPlayPrefsKey = "CompilingStopsPlay"; | |
[MenuItem("Window/Playmode Stop Options")] | |
static void Init() | |
{ | |
// Get existing open window or if none, make a new one: | |
var window = EditorWindow.GetWindow<EditorPlaymodeStop>(); | |
window.titleContent = new GUIContent("Preferences"); | |
window.Show(); | |
} | |
void OnGUI() | |
{ | |
GUILayout.Label("Should the editor stop play-mode automatically if it detects that the application is recompiling while playing?", EditorStyles.wordWrappedLabel); | |
bool shouldStop = EditorPrefs.GetBool(CompileStopsPlayPrefsKey, true); | |
bool shouldStopPrev = shouldStop; | |
shouldStop = EditorGUILayout.Toggle("Stop Play Automatically", shouldStop); | |
if (shouldStop != shouldStopPrev) | |
{ | |
EditorPrefs.SetBool(CompileStopsPlayPrefsKey, shouldStop); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment