Created
February 23, 2019 11:11
-
-
Save ZeredaGames/3839450a4b46de45b9a360846573c200 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
"#"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