Created
March 19, 2017 12:57
-
-
Save networm/ee057e757441e03215a656205b9c4d0a to your computer and use it in GitHub Desktop.
To do something before and after Unity play
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 UnityEngine; | |
using UnityEditor; | |
[InitializeOnLoad] | |
public class PlaymodeHook | |
{ | |
static PlaymodeHook() | |
{ | |
EditorApplication.update += Update; | |
EditorApplication.playmodeStateChanged += PlaymodeStateChanged; | |
} | |
private static void Update() | |
{ | |
if (!EditorApplication.isPlaying && | |
EditorApplication.isPlayingOrWillChangePlaymode) | |
{ | |
BeforeEnterPlaymode(); | |
} | |
} | |
private static void PlaymodeStateChanged() | |
{ | |
if (!EditorApplication.isPlaying && | |
!EditorApplication.isPlayingOrWillChangePlaymode) | |
{ | |
AfterExitPlaymode(); | |
} | |
} | |
private static void BeforeEnterPlaymode() | |
{ | |
Debug.Log("BeforeEnterPlaymode"); | |
} | |
private static void AfterExitPlaymode() | |
{ | |
Debug.Log("AfterExitPlaymode"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment