I am using my own custom external C# DLL for music, music loading, etc. Because I’m using an external DLL, I need to be able to inform my external threads when to start/stop. I can do this fine from within my game if it’s running start to finish with no interruption, but when I’m actually editing and debugging my game, I need to be able to know when the “Pause” or “Play/Stop” buttons have been hit inside the Unity IDE. This will allow me to clean up my external threads so I don’t have a bunch of mystery threads running when the program isn’t actually running inside the IDE.
I like to create a delegate method and assign it to handle play-mode changes, like so:
EditorApplication.playmodeStateChanged = HandleOnPlayModeChanged;
void HandleOnPlayModeChanged()
{
// This method is run whenever the playmode state is changed.
if (EditorApplication.isPaused)
{
// do stuff when the editor is paused.
}
}