当前位置:网站首页>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
边栏推荐
- 7. sub query
- 系统与软件安全研究(三)
- Online Safe Trajectory Generation For Quadrotors Using Fast Marching Method and Bernstein Basis Poly
- 13. User and authority management
- Authorization+Token+JWT
- Mvcc (multi version concurrency control)
- js之自定义属性以及H5中如何判断自定义属性
- 防抖和节流
- Redis connection error err auth < password > called without any password configured for the default user
- 基于NLP的软件安全研究(二)
猜你喜欢

Robust and Efficient Quadrotor Trajectory Generation for Fast Autonomous Flight

SAP RFC_CVI_EI_INBOUND_MAIN BP主数据创建示例(仅演示客户)

js之DOM事件

SAP PI/PO登录使用及基本功能简介

Implementation of MySQL persistence

Scrapy 修改爬虫结束时统计数据中的时间为当前系统时间

如何判断点是否在多边形内(包含复杂多边形或者多边形数量很多的情况)

'NPM' is not an internal or external command, nor is it a runnable program or batch file

Window10版MySQL设置远程访问权限后不起效果

设置了body的最大宽度,但是为什么body的背景颜色还铺满整个页面?
随机推荐
Two threads print odd and even numbers interactively
NodeJS(四) 字符读取
Xamarin版的C# SVG路径解析器
防抖和节流
12. Constraints
自己封装unity的Debug函数
js之自定义属性以及H5中如何判断自定义属性
js案例之求最大值,反转数组,冒泡排序
C#操作注册表全攻略
int a = 1存放在哪
FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning
SAP pi / PO rfc2soap publishes RFC interface as WS example
Django uses MySQL database to solve error reporting
斐波拉去动态规划
BTREE, B + tree and hash index
简单理解==和equals,String为什么可以不用new
Authorization+Token+JWT
Moment. Format of format method function in JS
RGB颜色转HEX进制与单位换算
Design optimization of MySQL database