diff --git a/Source/Editor/Editor.cs b/Source/Editor/Editor.cs
index 50de80e88..3098af5b6 100644
--- a/Source/Editor/Editor.cs
+++ b/Source/Editor/Editor.cs
@@ -216,6 +216,26 @@ namespace FlaxEditor
///
public ProjectInfo EngineProject;
+ ///
+ /// Occurs when play mode is beginning (before entering play mode).
+ ///
+ public event Action PlayModeBeginning;
+
+ ///
+ /// Occurs when play mode begins (after entering play mode).
+ ///
+ public event Action PlayModeBegin;
+
+ ///
+ /// Occurs when play mode is ending (before leaving play mode).
+ ///
+ public event Action PlayModeEnding;
+
+ ///
+ /// Occurs when play mode ends (after leaving play mode).
+ ///
+ public event Action PlayModeEnd;
+
internal Editor()
{
Instance = this;
@@ -523,16 +543,24 @@ namespace FlaxEditor
{
for (int i = 0; i < _modules.Count; i++)
_modules[i].OnPlayBeginning();
+ PlayModeBeginning?.Invoke();
}
internal void OnPlayBegin()
{
for (int i = 0; i < _modules.Count; i++)
_modules[i].OnPlayBegin();
+ PlayModeBegin?.Invoke();
+ }
+
+ internal void OnPlayEnding()
+ {
+ PlayModeEnding?.Invoke();
}
internal void OnPlayEnd()
{
+ PlayModeEnd?.Invoke();
for (int i = 0; i < _modules.Count; i++)
_modules[i].OnPlayEnd();
}
diff --git a/Source/Editor/States/PlayingState.cs b/Source/Editor/States/PlayingState.cs
index 90310ea13..334179ec6 100644
--- a/Source/Editor/States/PlayingState.cs
+++ b/Source/Editor/States/PlayingState.cs
@@ -171,6 +171,7 @@ namespace FlaxEditor.States
public override void OnExit(State nextState)
{
Profiler.BeginEvent("PlayingState.OnExit");
+ Editor.OnPlayEnding();
IsPaused = true;
// Remove references to the scene objects