简易消息管理器EventCenter
来源:互联网 发布:ubuntu u盘安装 编辑:程序博客网 时间:2024/06/06 02:08
/* * 日期:2017年7月4日 * 功能说明:消息中心,添加侦听,移除侦听,消息分发 * */using System;using System.Collections;using System.Collections.Generic;using UnityEngine;namespace BOFramework{ ////// 消息类,所有侦听消息和发送消息的参数,均以此为类型 /// 缺点:只能以此为参数类型,需要从object类型转到响应类型 /// public class EventMessage { public GameObject Sender; public object Param; public EventMessage(GameObject _sender, object _param) { this.Sender = _sender; this.Param = _param; } public EventMessage(object _param) { this.Sender = null; this.Param = _param; } public override string ToString() { return string.Format("sender={0},param={1}", this.Sender, this.Param); } } public delegate void EventDelegate(EventMessage msg); public class EventCenter { private static DictionaryDicEventData = new Dictionary (); private static Dictionary DicEventDatas = new Dictionary (); public static void OnListenerAdding(string _msgKey,Delegate _del) { if (!DicEventDatas.ContainsKey(_msgKey)) { DicEventDatas.Add(_msgKey,null); } DicEventDatas[_msgKey] = _del; } /// /// 添加监听事件 /// /// /// public static void AddListener(string _msgKey, EventDelegate _event) { if(!DicEventData.ContainsKey(_msgKey)) { DicEventData.Add(_msgKey, null); } DicEventData[_msgKey] += _event; } ////// 移除指定监听 /// /// public static void RemoveListener(string _msgKey) { if (!DicEventData.ContainsKey(_msgKey)) { DicEventData[_msgKey] = null; DicEventData.Remove(_msgKey); } } ////// 移除所有监听 /// public static void RemoveAllListener() { DicEventData.Clear(); } public static void BroadCastMessage(string _msgKey) { BroadCastMessage(_msgKey,null); } ////// 广播消息,带参数 /// /// /// public static void BroadCastMessage(string _msgKey, EventMessage _msg) { EventDelegate _eDeleg; if (DicEventData.TryGetValue(_msgKey, out _eDeleg)) { _eDeleg(_msg); } } }}
阅读全文
0 0
- 简易消息管理器EventCenter
- Common(五)—— 消息系统(一):简单的EventCenter
- 简易文件管理器
- android简易文件管理器
- Android简易任务管理器
- 简易文件管理器实现
- 简易管理器(驱动方式)
- 简易文件管理器
- ListView制作简易文件管理器
- python 简易ss端口管理器
- 简易文件管理器(未完成)
- 一个简易的文件管理器
- WPF实现简易任务管理器
- 游戏.消息管理器
- Android简易文件管理器的用法
- android简易文件管理器的用法
- android简易文件管理器的用法
- 消息队列管理器抽象工厂
- WUST OJ:2058: 划水的魅力(spfa)
- 欢迎使用CSDN-markdown编辑器
- celery初级教程(四)
- Cocos2dx锚点
- 金融系列-清结算在支付场景中如何应用
- 简易消息管理器EventCenter
- 4.dubbo源码分析 之 与Spring 集成
- eclipse4.7上的hibernate tools的离线安装问题。
- Spring IOC/BeanFactory/ApplicationContext的工作流程/实现原理/初始化/依赖注入源码详解
- 【练习】Mybatis简单配置(NetBeans下)
- 宏定义中的 ## ... __VA_ARGS__
- 862B Mahmoud and Ehab and the bipartiteness (黑白染色)
- Android使用iconfont
- TCP 三次握手和四次分手简析