Skip to content

Instantly share code, notes, and snippets.

@ZeredaGames
Created February 23, 2019 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZeredaGames/3839450a4b46de45b9a360846573c200 to your computer and use it in GitHub Desktop.
Save ZeredaGames/3839450a4b46de45b9a360846573c200 to your computer and use it in GitHub Desktop.
"#"region Update in editor NOT in play mode.// Remove the " "'s
"#"if UNITY_EDITOR// Remove the " "'s
[UnityEditor.Callbacks.DidReloadScripts]
public static void OnRecompiledScripts() {
UnityEditor.EditorApplication.playmodeStateChanged -= PlayModeStateChanged;
UnityEditor.EditorApplication.playmodeStateChanged += PlayModeStateChanged;
PlayModeStateChanged();
}
public static void PlayModeStateChanged() {
if(DebugMode)
Debug.Log("playmodeChanged");
if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode) {
toggle_allEditorUpdateHooks(false);
return;
}
//make sure all FSMs are getting updates
toggle_allEditorUpdateHooks(true);
}
private static void toggle_allEditorUpdateHooks(bool isTrue) {
MainGameManager[] myClasses = Component.FindObjectsOfType<MainGameManager>();
foreach (MainGameManager myClass in myClasses) {
myClass.toggle_EditorUpdateHook(isTrue);
}//end foreach
}
public void toggle_EditorUpdateHook(bool isOn) {
UnityEditor.EditorApplication.update -= UpdateInEditor;
if (isOn) {
UnityEditor.EditorApplication.update += UpdateInEditor;
}
}
private void UpdateInEditor() {
if(DebugMode)
Debug.Log("running in editor, every frame, but not while playing the game, pretty handy huh?");
if(Input.anyKeyDown){
InitializeManuallyMainGameManagerInstance();
}
}
#endif
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment