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) {