当前位置:网站首页>事件系统(二)多播事件
事件系统(二)多播事件
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
边栏推荐
- Ogldev reading notes
- Reflection on the systematic design of Android audio and video caching mechanism
- 2022.3.14 阿里笔试
- 设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?
- Simple random roll call lottery (written under JS)
- Page dynamic display time (upgraded version)
- SAP PI/PO功能运行状态监控检查
- new的实现
- Hot change scheme and dynamic update strategy of mobile game
- Judge whether the beginning and end of the string contain target parameters: startswith() and endswith() methods
猜你喜欢
js之预解析
Install and configure Taobao image NPM (cnpm)
Authorization server (simple construction of authorization server)
Solutions to common problems in visualization (VII) solutions to drawing scale setting
SAP RFC_CVI_EI_INBOUND_MAIN BP主数据创建示例(仅演示客户)
BTree、B+Tree和HASH索引
SAP SALV14 后台输出SALV数据可直接保存文件,发送Email(带排序、超链接、筛选格式)
h5本地存储数据sessionStorage、localStorage
‘npm‘不是内部或外部命令,也不是可运行的程序 或批处理文件
对js中argumens的简单理解
随机推荐
Super classic & Programming Guide (red and blue book) - Reading Notes
Learn to use search engines
系统与软件安全研究(一)
超级宝典&编程指南(红蓝宝书)-读书笔记
中间人环境mitmproxy搭建
Understanding of STL container
Mobile game performance optimization
对复杂字典Dictionary&lt;T1,T2&gt;排序问题
常用的DOS命令
SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)
js之DOM事件
学会使用搜索引擎
Apache Hudi 如何加速传统的批处理模式?
How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)
9. Common functions
Install and configure Taobao image NPM (cnpm)
SVG中Path Data数据简化及文件夹所有文件批量导出为图片
判断字符串首尾是否包含目标参数:startsWith()、endsWith()方法
What are the total number of all courses of Mr. Tang Xiaoyang, who is very popular in CSDN (question mark)
游戏辅助脚本开发之旅