From 8dce78d6fb6bd53aea0a29ec7907e2a8d2ded537 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Tue, 10 Oct 2023 18:13:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E6=A8=A1=E5=9D=97=E6=8B=93?= =?UTF-8?q?=E5=B1=95=E5=8F=82=E6=95=B0=E6=94=AF=E6=8C=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 事件模块拓展参数支持。 --- .../Core/GameEvent/EventDelegateData.cs | 30 +++++++++++++++ .../Runtime/Core/GameEvent/EventDispatcher.cs | 23 +++++++++++ .../Runtime/Core/GameEvent/GameEvent.cs | 38 +++++++++++++++++++ 3 files changed, 91 insertions(+) diff --git a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/EventDelegateData.cs b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/EventDelegateData.cs index 4b6925f0..f503c483 100644 --- a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/EventDelegateData.cs +++ b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/EventDelegateData.cs @@ -231,5 +231,35 @@ namespace TEngine CheckModify(); } + + /// + /// 回调调用。 + /// + /// 事件参数1。 + /// 事件参数2。 + /// 事件参数3。 + /// 事件参数4。 + /// 事件参数5。 + /// 事件参数6。 + /// 事件参数1类型。 + /// 事件参数2类型。 + /// 事件参数3类型。 + /// 事件参数4类型。 + /// 事件参数5类型。 + /// 事件参数6类型。 + public void Callback(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6) + { + _isExecute = true; + for (var i = 0; i < _listExist.Count; i++) + { + var d = _listExist[i]; + if (d is Action action) + { + action(arg1, arg2, arg3, arg4, arg5, arg6); + } + } + + CheckModify(); + } } } \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/EventDispatcher.cs b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/EventDispatcher.cs index 7f319e5b..4ba105e3 100644 --- a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/EventDispatcher.cs +++ b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/EventDispatcher.cs @@ -151,6 +151,29 @@ namespace TEngine } } + /// + /// 发送事件。 + /// + /// 事件类型。 + /// 事件参数1。 + /// 事件参数2。 + /// 事件参数3。 + /// 事件参数4。 + /// 事件参数5。 + /// 事件参数6。 + /// 事件参数1类型。 + /// 事件参数2类型。 + /// 事件参数3类型。 + /// 事件参数4类型。 + /// 事件参数5类型。 + /// 事件参数6类型。 + public void Send(int eventType, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6) + { + if (_eventTable.TryGetValue(eventType, out var d)) + { + d.Callback(arg1, arg2, arg3, arg4, arg5, arg6); + } + } #endregion } } \ 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 5039c8fc..c866890f 100644 --- a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/GameEvent.cs +++ b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/GameEvent.cs @@ -94,6 +94,23 @@ namespace TEngine { return _eventMgr.Dispatcher.AddEventListener(eventType, handler); } + + /// + /// 增加事件监听。 + /// + /// 事件类型。 + /// 事件处理回调。 + /// 事件参数1类型。 + /// 事件参数2类型。 + /// 事件参数3类型。 + /// 事件参数4类型。 + /// 事件参数5类型。 + /// 事件参数6类型。 + /// + public static bool AddEventListener(int eventType, Action handler) + { + return _eventMgr.Dispatcher.AddEventListener(eventType, handler); + } /// /// 移除事件监听。 @@ -534,6 +551,27 @@ namespace TEngine { _eventMgr.Dispatcher.Send(RuntimeId.ToRuntimeId(eventType), arg1, arg2, arg3, arg4, arg5); } + + /// + /// + /// + /// 事件类型。 + /// 事件参数1。 + /// 事件参数2。 + /// 事件参数3。 + /// 事件参数4。 + /// 事件参数5。 + /// 事件参数6。 + /// 事件参数1类型。 + /// 事件参数2类型。 + /// 事件参数3类型。 + /// 事件参数4类型。 + /// 事件参数5类型。 + /// 事件参数6类型。 + public static void Send(int eventType, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6) + { + _eventMgr.Dispatcher.Send(eventType, arg1, arg2, arg3, arg4, arg5, arg6); + } /// ///