当前位置:网站首页>事件系统(二)多播事件
事件系统(二)多播事件
2022-04-23 06:27:00 【老少年】
先创建字典保存所有的事件
Dictionary<EPlayerEvt, List<Action<object, object[]>>> _phList = new Dictionary<EPlayerEvt, List<Action<object, object[]>>>();
1.事件添加
public void addEventHandler(EPlayerEvt eventID, Action<object, object[]> handler)
{
if (_phList == null) return;
if (!_phList.ContainsKey(eventID)){
_phList[eventID] = new List<Action<object, object[]>>();
}
var funcList = _phList[eventID];
if (funcList == null) return;
funcList.Add(handler);
}
2.事件删除
public void delEventHandler(EPlayerEvt eventID, Action<object, object[]> handler)
{
if (_phList.ContainsKey(eventID))
{
var funcList = _phList[eventID];
var action = funcList.Find(i=> i == handler);
if (action != null)
{
funcList.Remove(action);
}
}
}
3.事件触发
public void fireEvent(EPlayerEvt eventID, object sender, object[] args)
{
if (_phList.ContainsKey(eventID))
{
var actList = _phList[eventID];
if (actList != null)
{
for (int i = 0; i < actList.Count; i++)
{
var item = actList[i];
if (item != null)
{
item(sender, args);
}
}
}
}
}
4.删除所有事件
public void delAllEventHandler(EPlayerEvt eventID)
{
if (_phList.ContainsKey(eventID))
{
var funcList = _phList[eventID];
if (funcList != null)
{
funcList.Clear();
}
}
}
5.重置事件系统
public void Reset()
{
if (_phList == null) return;
_phList.Clear();
_phList = null;
}
版权声明
本文为[老少年]所创,转载请带上原文链接,感谢
https://blog.csdn.net/laoshaonian/article/details/89330799
边栏推荐
猜你喜欢
redis连接出错 ERR AUTH <password> called without any password configured for the default user.
王者荣耀-unity学习之旅
SAP DEBUG调试FOR IN、REDUCE等复杂的语句
BTree、B+Tree和HASH索引
Super classic & Programming Guide (red and blue book) - Reading Notes
SVG中Path Data数据简化及文件夹所有文件批量导出为图片
防抖和节流
ABAP 实现发布RESTful服务供外部调用示例
Date对象(js内置对象)
Design optimization of MySQL database
随机推荐
快排的练习
中间人环境mitmproxy搭建
redis连接出错 ERR AUTH <password> called without any password configured for the default user.
promise all的实现
SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)
Implementation of MySQL persistence
The difference and application of VR, AR and MR, as well as some implementation principles of AR technology
Moment. Format of format method function in JS
4. Multi table query
系统与软件安全研究(二)
js之DOM事件
6.聚合函数和分组统计
超级宝典&编程指南(红蓝宝书)-读书笔记
canvas学习第一篇
C# 文本文件的查找及替换(WinForm)
9. Common functions
5. Sql99 standard: internal connection and external connection
Date对象(js内置对象)
C#使用拉依达准则(3σ准则)剔除异常数据(.Net剔除一组数据中的奇异值)
Preliminary configuration of OpenGL super Dictionary (freeglut, glew, gltools, GLUT)