当前位置:网站首页>One of event management
One of event management
2022-04-23 07:47:00 【youth who behaves like an adult】
public enum EUIMgrEvent
{
onUILogInOpend,
onUILogInClose,
onUIHintOpend,
onUIHintClose,
onUIWorkOpend,
onUIWorkClose,
onUIShopOpend,
onUIShopClose
}
First create several event types , Then add the event type , Trigger , Delete and other operations ..........
1. Create a dictionary to save events
Dictionary<EUIMgrEvent, Action<object, object[]>> _phList = new Dictionary<EUIMgrEvent, Action<object, object[]>>();
2. Add event
public void addEventHandler(EUIMgrEvent eventID,Action<object, object[]> handler)
{
if (_phList == null) return;
if (_phList.ContainsKey(eventID))
{
Debug.LogError(string.Format("error: event[ {0} ] already exists", eventID));
return;
}
_phList[eventID] = handler;
}
3. Delete event
public void delEventHandler(EUIMgrEvent eventID)
{
if (_phList == null) return;
if (!_phList.ContainsKey(eventID))
{
Debug.LogError(string.Format("error: event[ {0} ] not exists", eventID));
return;
}
_phList.Remove(eventID);
}
4. Triggering event
public void fireEvent(EUIMgrEvent eventID,object sender ,object[] args)
{
if (_phList == null) return;
if (!_phList.ContainsKey(eventID)){
return;
}
var action = _phList[eventID];
if (action == null) return;
action(sender, args);
}
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/202204230626191374.html
边栏推荐
猜你喜欢
随机推荐
系统与软件安全研究(三)
将指定路径下的所有SVG文件导出成PNG等格式的图片(缩略图或原图大小)
BTree、B+Tree和HASH索引
js之什么是事件?事件三要素以及操作元素
保研准备经验贴——18届(2021年)中南计科推免到浙大工院
js之作用域、作用域链、全局变量和局部变量
js之排他思想及案例
unity 屏幕自适应
How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)
2. Restricted query
keytool: command not found
Thorough inquiry -- understanding and analysis of cocos2d source code
对复杂字典Dictionary&lt;T1,T2&gt;排序问题
Apache Hudi 如何加速传统的批处理模式?
MySQL8.0 安装/卸载 教程【Window10版】
定位、修饰样式
【NLP笔记】CRF原理初探
js之函数的两种声明方式
Moment. Format of format method function in JS
SVG中年月日相关的表达式