Add public events for Editor play mode flow

This commit is contained in:
Wojtek Figat
2022-05-03 23:08:47 +02:00
parent bc6b70f4f9
commit 2a4057cbc2
2 changed files with 29 additions and 0 deletions

View File

@@ -216,6 +216,26 @@ namespace FlaxEditor
/// </summary>
public ProjectInfo EngineProject;
/// <summary>
/// Occurs when play mode is beginning (before entering play mode).
/// </summary>
public event Action PlayModeBeginning;
/// <summary>
/// Occurs when play mode begins (after entering play mode).
/// </summary>
public event Action PlayModeBegin;
/// <summary>
/// Occurs when play mode is ending (before leaving play mode).
/// </summary>
public event Action PlayModeEnding;
/// <summary>
/// Occurs when play mode ends (after leaving play mode).
/// </summary>
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();
}

View File

@@ -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