Skip to content

Instantly share code, notes, and snippets.

@networm
Created March 19, 2017 12:57
Show Gist options
  • Save networm/ee057e757441e03215a656205b9c4d0a to your computer and use it in GitHub Desktop.
Save networm/ee057e757441e03215a656205b9c4d0a to your computer and use it in GitHub Desktop.
To do something before and after Unity play
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