From 4c0f5a77f932d0eb70a1c7be666ae20a37f9069d Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Tue, 7 May 2024 18:05:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=BC=96=E8=BE=91=E5=99=A8?= =?UTF-8?q?=E4=B8=8BEnterPlayMode=20Options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Event/RegisterEventInterface_Logic.cs | 1 + .../Runtime/Core/GameEvent/EventMgr.cs | 13 ++++++-- .../Runtime/Core/GameEvent/GameEvent.cs | 8 +++++ .../TEngine/Runtime/Modules/GameModule.cs | 30 +++++++++++++++++++ .../Modules/ModuleCore/ModuleSystem.cs | 1 + 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Event/RegisterEventInterface_Logic.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Event/RegisterEventInterface_Logic.cs index 45a26dc1..0ec605b6 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Event/RegisterEventInterface_Logic.cs +++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Event/RegisterEventInterface_Logic.cs @@ -34,6 +34,7 @@ namespace GameLogic object obj = Activator.CreateInstance(type, mgr.Dispatcher); + mgr.Init(); mgr.RegWrapInterface(obj.GetType().GetInterfaces()[0]?.FullName, obj); } } diff --git a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/EventMgr.cs b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/EventMgr.cs index feb2d265..941e60bc 100644 --- a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/EventMgr.cs +++ b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/EventMgr.cs @@ -62,13 +62,22 @@ namespace TEngine entry.InterfaceWrap = callerWrap; if (typeName != null) { - _eventEntryMap.Add(typeName, entry); + _eventEntryMap[typeName] = entry; } } /// /// 分发注册器。 /// - public EventDispatcher Dispatcher { get; } = new EventDispatcher(); + public EventDispatcher Dispatcher { get; private set; } = new EventDispatcher(); + + /// + /// 清除事件。 + /// + public void Init() + { + _eventEntryMap.Clear(); + Dispatcher = new EventDispatcher(); + } } } \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/GameEvent.cs b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/GameEvent.cs index bc7e52e3..541d21d2 100644 --- a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/GameEvent.cs +++ b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/GameEvent.cs @@ -585,5 +585,13 @@ namespace TEngine } #endregion + + /// + /// 清除事件。 + /// + public static void Shutdown() + { + _eventMgr.Init(); + } } } \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/GameModule.cs b/UnityProject/Assets/TEngine/Runtime/Modules/GameModule.cs index e4babd7f..5b9a6ef3 100644 --- a/UnityProject/Assets/TEngine/Runtime/Modules/GameModule.cs +++ b/UnityProject/Assets/TEngine/Runtime/Modules/GameModule.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; using UnityEngine; +#if UNITY_EDITOR +using UnityEditor; +#endif namespace TEngine { @@ -170,5 +173,32 @@ namespace TEngine _timer = null; _resourceExt = null; } + + #region HandlePlayModeStateChanged + private void OnEnable() + { +#if UNITY_EDITOR + EditorApplication.playModeStateChanged += HandlePlayModeStateChanged; +#endif + } + + private void OnDisable() + { +#if UNITY_EDITOR + EditorApplication.playModeStateChanged -= HandlePlayModeStateChanged; +#endif + } + +#if UNITY_EDITOR + void HandlePlayModeStateChanged(PlayModeStateChange state) + { + if (state == PlayModeStateChange.ExitingPlayMode) + { + ModuleSystem.Shutdown(ShutdownType.Quit); + } + } +#endif + #endregion + } } \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ModuleCore/ModuleSystem.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ModuleCore/ModuleSystem.cs index a71dc974..82857706 100644 --- a/UnityProject/Assets/TEngine/Runtime/Modules/ModuleCore/ModuleSystem.cs +++ b/UnityProject/Assets/TEngine/Runtime/Modules/ModuleCore/ModuleSystem.cs @@ -87,6 +87,7 @@ namespace TEngine _modules.Clear(); GameModule.Shutdown(shutdownType); + GameEvent.Shutdown(); if (shutdownType == ShutdownType.None) {