From 2a4057cbc24e5af1daea9c6f766d311cdc42e538 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 May 2022 23:08:47 +0200 Subject: [PATCH] Add public events for Editor play mode flow --- Source/Editor/Editor.cs | 28 ++++++++++++++++++++++++++++ Source/Editor/States/PlayingState.cs | 1 + 2 files changed, 29 insertions(+) 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