当前位置:网站首页>Event system (II) multicast events
Event system (II) multicast events
2022-04-23 07:47:00 【youth who behaves like an adult】
First create a dictionary to save all events
Dictionary<EPlayerEvt, List<Action<object, object[]>>> _phList = new Dictionary<EPlayerEvt, List<Action<object, object[]>>>();
1. Events add
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. Event deletion
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. Events trigger
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. Delete all events
public void delAllEventHandler(EPlayerEvt eventID)
{
if (_phList.ContainsKey(eventID))
{
var funcList = _phList[eventID];
if (funcList != null)
{
funcList.Clear();
}
}
}
5. Reset event system
public void Reset()
{
if (_phList == null) return;
_phList.Clear();
_phList = null;
}
版权声明
本文为[youth who behaves like an adult]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230626191333.html
边栏推荐
- js之节点操作,为什么要学习节点操作
- 中间人环境mitmproxy搭建
- js之排他思想及案例
- Online Safe Trajectory Generation For Quadrotors Using Fast Marching Method and Bernstein Basis Poly
- 给定区段范围内字符串自生成代码
- Mongodb 启动警告信息处理
- keytool: command not found
- FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning
- 保研准备经验贴——18届(2021年)中南计科推免到浙大工院
- 7. sub query
猜你喜欢
SAP pi / PO rfc2soap publishes RFC interface as WS example
Authorization server (simple construction of authorization server)
SAP ECC连接SAP PI系统配置
keytool: command not found
Super classic & Programming Guide (red and blue book) - Reading Notes
中间人环境mitmproxy搭建
命令行参数传递库argparse的使用
Authorization+Token+JWT
js之排他思想及案例
SAP PI/PO功能运行状态监控检查
随机推荐
Two threads print odd and even numbers interactively
14. Transaction processing
12. Constraints
2. Restricted query
SVG中Path Data数据简化及文件夹所有文件批量导出为图片
面经总结2
2022.3.14 Ali written examination
事件管理之一
instanceof的实现原理
Page dynamic display time (upgraded version)
Solutions to common problems in visualization (VII) solutions to drawing scale setting
NodeJS(六) 子进程操作
将单行文字自动适应到目标矩形框内
SampleCameraFilter
异步的学习
Moment. Format of format method function in JS
对复杂字典Dictionary&lt;T1,T2&gt;排序问题
Hot change scheme and dynamic update strategy of mobile game
js之预解析
js中对象的三种创建方式