IndieGame/client/Assets/Ether/Scripts/Common/EventCenter/EventCenter.cs

583 lines
19 KiB
C#
Raw Normal View History

2024-10-11 10:12:15 +08:00
/********************************************************************
: EventCenter.cs
:
: 1982614048@qq.com
: 2024/03/29 17:28:19
:
: 2024/04/03 16:06:58
:
使:
AddListener:
EventCenter.AddListener<NetProtoType, IOCPServerSession, byte[]>(NetProtoType.IOCPReceive, IOCPMsgReceive);
EventCenter.AddListener<MsgId, HttpListenerResponse, MsgData>(MsgId.Regist, RegistEventDispose);
RemoveListener:
EventCenter.RemoveListener<NetProtoType, IOCPServerSession, byte[]>(NetProtoType.IOCPReceive, IOCPMsgReceive);
EventCenter.RemoveListener<MsgId, HttpListenerResponse, MsgData>(MsgId.Regist, RegistEventDispose);
BroadCast:
EventCenter.BroadCast((MsgId)msgData.msgId, session, msgData);
EventCenter.BroadCast(NetProtoType.HTTPPostReceive, response, content);
*********************************************************************/
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// 事件处理
/// </summary>
public class EventCenter
{
2024-10-28 18:20:21 +08:00
#region
2024-10-11 10:12:15 +08:00
2024-11-01 14:07:47 +08:00
private static Dictionary<string, Delegate> allEventDic = new Dictionary<string, Delegate>();
2024-10-11 10:12:15 +08:00
2024-11-01 14:07:47 +08:00
private static void OnListenerAdding(string eventType, Delegate callback)
2024-10-28 18:20:21 +08:00
{
2024-11-01 14:07:47 +08:00
allEventDic.TryAdd(eventType, null);
2024-10-11 10:12:15 +08:00
2024-11-01 14:07:47 +08:00
Delegate d = allEventDic[eventType];
2024-10-11 10:12:15 +08:00
2024-11-01 14:07:47 +08:00
if (!string.IsNullOrEmpty(eventType) && d != null && d.GetType() != callback.GetType())
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
throw new Exception($"尝试为事件{eventType}添加不同类型的委托,当前事件所对应的委托为{d.GetType()},要添加的委托类型为{callback.GetType()}");
2024-10-11 10:12:15 +08:00
}
}
2024-11-01 14:07:47 +08:00
private static void OnListenerRemoving(string eventType, Delegate callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
if (allEventDic.ContainsKey(eventType))
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
Delegate d = allEventDic[eventType];
2024-10-28 18:20:21 +08:00
if (d == null)
{
throw new Exception($"移除监听错误:事件{eventType}没有对应的委托");
}
2024-11-01 14:07:47 +08:00
else if (d.GetType() != callback.GetType())
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
throw new Exception(
2024-11-01 14:07:47 +08:00
$"移除监听错误:尝试为事件{eventType}移除不同类型的委托,当前委托类型为{d.GetType()},要移除的委托类型为{callback.GetType()}");
2024-10-11 10:12:15 +08:00
}
2024-10-28 18:20:21 +08:00
return;
2024-10-11 10:12:15 +08:00
}
2024-10-28 18:20:21 +08:00
throw new Exception($"移除监听错误:没有事件码{eventType}");
2024-10-11 10:12:15 +08:00
}
2024-10-28 18:20:21 +08:00
private static void OnListenerRemoved(string eventType)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
if (allEventDic[eventType] == null)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
allEventDic.Remove(eventType);
2024-10-11 10:12:15 +08:00
}
}
//==================================================监听事件========================================================
/// <summary>
/// 无参数监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void AddListener(string eventType, Action callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
OnListenerAdding(eventType, callback);
allEventDic[eventType] = (Action)allEventDic[eventType] + callback;
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 一个参数监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void AddListener<K>(string eventType, Action<K> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
OnListenerAdding(eventType, callback);
allEventDic[eventType] = (Action<K>)allEventDic[eventType] + callback;
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 两个参数监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void AddListener<K, X>(string eventType, Action<K, X> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
OnListenerAdding(eventType, callback);
allEventDic[eventType] = (Action<K, X>)allEventDic[eventType] + callback;
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 三个参数监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void AddListener<K, X, Y>(string eventType, Action<K, X, Y> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
OnListenerAdding(eventType, callback);
allEventDic[eventType] = (Action<K, X, Y>)allEventDic[eventType] + callback;
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 四个参数监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void AddListener<K, X, Y, Z>(string eventType, Action<K, X, Y, Z> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
OnListenerAdding(eventType, callback);
allEventDic[eventType] = (Action<K, X, Y, Z>)allEventDic[eventType] + callback;
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 五个参数监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void AddListener<K, X, Y, Z, W>(string eventType, Action<K, X, Y, Z, W> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
OnListenerAdding(eventType, callback);
allEventDic[eventType] = (Action<K, X, Y, Z, W>)allEventDic[eventType] + callback;
2024-10-11 10:12:15 +08:00
}
//==================================================移除监听========================================================
/// <summary>
/// 无参移除监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void RemoveListener(string eventType, Action callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
OnListenerRemoving(eventType, callback);
allEventDic[eventType] = (Action)allEventDic[eventType] - callback;
2024-10-11 10:12:15 +08:00
OnListenerRemoved(eventType);
}
/// <summary>
/// 一个参数移除监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void RemoveListener<K>(string eventType, Action<K> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
OnListenerRemoving(eventType, callback);
allEventDic[eventType] = (Action<K>)allEventDic[eventType] - callback;
2024-10-11 10:12:15 +08:00
OnListenerRemoved(eventType);
}
/// <summary>
/// 两个参数移除监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void RemoveListener<K, X>(string eventType, Action<K, X> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
OnListenerRemoving(eventType, callback);
allEventDic[eventType] = (Action<K, X>)allEventDic[eventType] - callback;
2024-10-11 10:12:15 +08:00
OnListenerRemoved(eventType);
}
/// <summary>
/// 三个参数移除监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void RemoveListener<K, X, Y>(string eventType, Action<K, X, Y> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
OnListenerRemoving(eventType, callback);
allEventDic[eventType] = (Action<K, X, Y>)allEventDic[eventType] - callback;
2024-10-11 10:12:15 +08:00
OnListenerRemoved(eventType);
}
/// <summary>
/// 四个参数移除监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void RemoveListener<K, X, Y, Z>(string eventType, Action<K, X, Y, Z> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
OnListenerRemoving(eventType, callback);
allEventDic[eventType] = (Action<K, X, Y, Z>)allEventDic[eventType] - callback;
2024-10-11 10:12:15 +08:00
OnListenerRemoved(eventType);
}
/// <summary>
/// 五个参数移除监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void RemoveListener<K, X, Y, Z, W>(string eventType, Action<K, X, Y, Z, W> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
OnListenerRemoving(eventType, callback);
allEventDic[eventType] = (Action<K, X, Y, Z, W>)allEventDic[eventType] - callback;
2024-10-11 10:12:15 +08:00
OnListenerRemoved(eventType);
}
2024-11-01 14:07:47 +08:00
public static void RemoveListener(string eventType, Delegate callback)
{
// 如果 dictB 中存在相同的键
if (allEventDic.ContainsKey(eventType))
{
// 获取 MulticastDelegate
MulticastDelegate multicastDelegate = allEventDic[eventType] as MulticastDelegate;
// 移除指定的委托
Delegate[] invocationList = multicastDelegate.GetInvocationList();
Delegate[] newInvocationList = Array.FindAll(invocationList, d => d != callback);
// 更新 dictB 中的委托
if (newInvocationList.Length > 0)
{
allEventDic[eventType] = Delegate.Combine(newInvocationList);
}
else
{
// 如果没有剩余的委托,则从 dictB 中删除该键
allEventDic.Remove(eventType);
}
}
}
2024-10-11 10:12:15 +08:00
//==================================================广播事件========================================================
/// <summary>
/// 无参广播事件
/// </summary>
/// <param name="eventType">事件</param>
2024-10-28 18:20:21 +08:00
public static void BroadCast(string eventType)
2024-10-11 10:12:15 +08:00
{
Delegate d;
2024-11-01 14:07:47 +08:00
if (allEventDic.TryGetValue(eventType, out d))
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
if (d is Action callback)
2024-10-28 18:20:21 +08:00
{
2024-11-01 14:07:47 +08:00
callback();
2024-10-28 18:20:21 +08:00
}
else
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
throw new Exception($"广播事件错误:事件{eventType}对应委托具有不同的类型");
2024-10-11 10:12:15 +08:00
}
}
}
/// <summary>
/// 一个参数广播事件
/// </summary>
/// <param name="eventType">事件</param>
2024-10-28 18:20:21 +08:00
public static void BroadCast<K>(string eventType, K arg)
2024-10-11 10:12:15 +08:00
{
Delegate d;
2024-11-01 14:07:47 +08:00
if (allEventDic.TryGetValue(eventType, out d))
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
if (d is Action<K> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
callback(arg);
2024-10-28 18:20:21 +08:00
}
else
{
throw new Exception($"广播事件错误:事件{eventType}对应委托具有不同的类型");
2024-10-11 10:12:15 +08:00
}
}
}
/// <summary>
/// 两个参数广播事件
/// </summary>
/// <param name="eventType">事件</param>
2024-10-28 18:20:21 +08:00
public static void BroadCast<K, X>(string eventType, K arg1, X arg2)
2024-10-11 10:12:15 +08:00
{
Delegate d;
2024-11-01 14:07:47 +08:00
if (allEventDic.TryGetValue(eventType, out d))
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
if (d is Action<K, X> callback)
2024-10-28 18:20:21 +08:00
{
2024-11-01 14:07:47 +08:00
callback(arg1, arg2);
2024-10-28 18:20:21 +08:00
}
else
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
throw new Exception($"广播事件错误:事件{eventType}对应委托具有不同的类型");
2024-10-11 10:12:15 +08:00
}
}
}
/// <summary>
/// 三个参数广播事件
/// </summary>
/// <param name="eventType">事件</param>
2024-10-28 18:20:21 +08:00
public static void BroadCast<K, X, Y>(string eventType, K arg1, X arg2, Y arg3)
2024-10-11 10:12:15 +08:00
{
Delegate d;
2024-11-01 14:07:47 +08:00
if (allEventDic.TryGetValue(eventType, out d))
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
if (d is Action<K, X, Y> callback)
2024-10-28 18:20:21 +08:00
{
2024-11-01 14:07:47 +08:00
callback(arg1, arg2, arg3);
2024-10-28 18:20:21 +08:00
}
else
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
throw new Exception($"广播事件错误:事件{eventType}对应委托具有不同的类型");
2024-10-11 10:12:15 +08:00
}
}
}
/// <summary>
/// 四个参数广播事件
/// </summary>
/// <param name="eventType">事件</param>
2024-10-28 18:20:21 +08:00
public static void BroadCast<K, X, Y, Z>(string eventType, K arg1, X arg2, Y arg3, Z arg4)
2024-10-11 10:12:15 +08:00
{
Delegate d;
2024-11-01 14:07:47 +08:00
if (allEventDic.TryGetValue(eventType, out d))
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
if (d is Action<K, X, Y, Z> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
callback(arg1, arg2, arg3, arg4);
2024-10-28 18:20:21 +08:00
}
else
{
throw new Exception($"广播事件错误:事件{eventType}对应委托具有不同的类型");
2024-10-11 10:12:15 +08:00
}
}
}
/// <summary>
/// 五个参数广播事件
/// </summary>
/// <param name="eventType">事件</param>
2024-10-28 18:20:21 +08:00
public static void BroadCast<K, X, Y, Z, W>(string eventType, K arg1, X arg2, Y arg3, Z arg4, W arg5)
2024-10-11 10:12:15 +08:00
{
Delegate d;
2024-11-01 14:07:47 +08:00
if (allEventDic.TryGetValue(eventType, out d))
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
if (d is Action<K, X, Y, Z, W> callback)
2024-10-11 10:12:15 +08:00
{
2024-11-01 14:07:47 +08:00
callback(arg1, arg2, arg3, arg4, arg5);
2024-10-11 10:12:15 +08:00
}
2024-10-28 18:20:21 +08:00
else
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
throw new Exception($"广播事件错误:事件{eventType}对应委托具有不同的类型");
2024-10-11 10:12:15 +08:00
}
}
}
2024-10-28 18:20:21 +08:00
#endregion
#region
2024-10-11 10:12:15 +08:00
//==================================================监听事件========================================================
/// <summary>
/// 无参数监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void AddListener<T>(T eventType, Action callback) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
2024-11-01 14:07:47 +08:00
AddListener(eventName, callback);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 一个参数监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void AddListener<T, K>(T eventType, Action<K> callback) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
2024-11-01 14:07:47 +08:00
AddListener(eventName, callback);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 两个参数监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void AddListener<T, K, X>(T eventType, Action<K, X> callback) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
2024-11-01 14:07:47 +08:00
AddListener(eventName, callback);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 三个参数监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void AddListener<T, K, X, Y>(T eventType, Action<K, X, Y> callback) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
2024-11-01 14:07:47 +08:00
AddListener(eventName, callback);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 四个参数监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void AddListener<T, K, X, Y, Z>(T eventType, Action<K, X, Y, Z> callback) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
2024-11-01 14:07:47 +08:00
AddListener(eventName, callback);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 五个参数监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void AddListener<T, K, X, Y, Z, W>(T eventType, Action<K, X, Y, Z, W> callback) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
2024-11-01 14:07:47 +08:00
AddListener(eventName, callback);
2024-10-11 10:12:15 +08:00
}
//==================================================移除监听========================================================
/// <summary>
/// 无参移除监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void RemoveListener<T>(T eventType, Action callback) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
2024-11-01 14:07:47 +08:00
RemoveListener(eventName, callback);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 一个参数移除监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void RemoveListener<T, K>(T eventType, Action<K> callback) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
2024-11-01 14:07:47 +08:00
RemoveListener(eventName, callback);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 两个参数移除监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void RemoveListener<T, K, X>(T eventType, Action<K, X> callback) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
2024-11-01 14:07:47 +08:00
RemoveListener(eventName, callback);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 三个参数移除监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void RemoveListener<T, K, X, Y>(T eventType, Action<K, X, Y> callback) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
2024-11-01 14:07:47 +08:00
RemoveListener(eventName, callback);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 四个参数移除监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void RemoveListener<T, K, X, Y, Z>(T eventType, Action<K, X, Y, Z> callback) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
2024-11-01 14:07:47 +08:00
RemoveListener(eventName, callback);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 五个参数移除监听
/// </summary>
/// <param name="eventType">事件</param>
2024-11-01 14:07:47 +08:00
/// <param name="callback">回调</param>
public static void RemoveListener<T, K, X, Y, Z, W>(T eventType, Action<K, X, Y, Z, W> callback) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
2024-11-01 14:07:47 +08:00
RemoveListener(eventName, callback);
2024-10-11 10:12:15 +08:00
}
//==================================================广播事件========================================================
/// <summary>
/// 无参广播事件
/// </summary>
/// <param name="eventType">事件</param>
2024-10-28 18:20:21 +08:00
public static void BroadCast<T>(T eventType) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
BroadCast(eventName);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 一个参数广播事件
/// </summary>
/// <param name="eventType">事件</param>
2024-10-28 18:20:21 +08:00
public static void BroadCast<T, K>(T eventType, K arg) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
BroadCast(eventName, arg);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 两个参数广播事件
/// </summary>
/// <param name="eventType">事件</param>
2024-10-28 18:20:21 +08:00
public static void BroadCast<T, K, X>(T eventType, K arg1, X arg2) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
BroadCast(eventName, arg1, arg2);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 三个参数广播事件
/// </summary>
/// <param name="eventType">事件</param>
2024-10-28 18:20:21 +08:00
public static void BroadCast<T, K, X, Y>(T eventType, K arg1, X arg2, Y arg3) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
BroadCast(eventName, arg1, arg2, arg3);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 四个参数广播事件
/// </summary>
/// <param name="eventType">事件</param>
2024-10-28 18:20:21 +08:00
public static void BroadCast<T, K, X, Y, Z>(T eventType, K arg1, X arg2, Y arg3, Z arg4) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
BroadCast(eventName, arg1, arg2, arg3, arg4);
2024-10-11 10:12:15 +08:00
}
/// <summary>
/// 五个参数广播事件
/// </summary>
/// <param name="eventType">事件</param>
2024-10-28 18:20:21 +08:00
public static void BroadCast<T, K, X, Y, Z, W>(T eventType, K arg1, X arg2, Y arg3, Z arg4, W arg5) where T : Enum
2024-10-11 10:12:15 +08:00
{
2024-10-28 18:20:21 +08:00
string eventName = $"{eventType.GetType()}_{eventType.ToString()}";
BroadCast(eventName, arg1, arg2, arg3, arg4, arg5);
2024-10-11 10:12:15 +08:00
}
#endregion
/// <summary>
/// 清理
/// </summary>
public static void Clear()
{
2024-11-01 14:07:47 +08:00
allEventDic.Clear();
2024-10-11 10:12:15 +08:00
}
2024-11-01 14:07:47 +08:00
2024-10-11 10:12:15 +08:00
}