Unity_内部消息机制
来源:互联网 发布:改造农村老房子 知乎 编辑:程序博客网 时间:2024/06/05 14:14
using UnityEngine;using System.Collections;using System.Collections.Generic;using System;using GameType;public class Messenger{ private static Dictionary<ClickType, Delegate> mDict = new Dictionary<ClickType, Delegate>(); private static bool OnAddListener(ClickType type,Delegate handler) { if (!mDict.ContainsKey(type)) { mDict.Add(type, null); } Delegate d = mDict[type]; if (d != null && d.GetType()!=handler.GetType()) { return false; } return true; } private static bool OnRemoveListener(ClickType type,Delegate handler) { if (mDict.ContainsKey(type)) { Delegate d = mDict[type]; if (d==null) { return false; } else if (d.GetType()!=handler.GetType()) { return false; } } else { return false; } return true; } public static void AddListener(ClickType type,Callback handler) { if (!OnAddListener(type,handler)) { return; } mDict[type] = (Callback)mDict[type] + handler; } public static void AddListener<T>(ClickType type,Callback<T> handler) { if (!OnAddListener(type,handler)) { return; } mDict[type] = (Callback<T>)mDict[type] + handler; } public static void RemoveListener(ClickType type,Callback handler) { if (!OnRemoveListener(type,handler)) { return; } mDict[type] = (Callback)mDict[type] - handler; if (mDict[type]==null) { mDict.Remove(type); } } public static void RemoveListener<T>(ClickType type,Callback<T> handler) { if (!OnRemoveListener(type, handler)) { return; } mDict[type] = (Callback<T>)mDict[type] - handler; if (mDict[type] == null) { mDict.Remove(type); } } public static void Broadcast(ClickType type) { if (!mDict.ContainsKey(type)) { return; } Delegate d; if(mDict.TryGetValue(type, out d)) { Callback callback = d as Callback; if (callback != null) callback(); else return; } } public static void Broadcast<T>(ClickType type,T arg) { if (!mDict.ContainsKey(type)) { return; } Delegate d; if (mDict.TryGetValue(type, out d)) { Callback<T> callback = d as Callback<T>; if (callback != null) callback(arg); else return; } }}
阅读全文
0 0
- Unity_内部消息机制
- 内部消息机制
- YATE内部的消息机制
- YATE内部的消息机制
- Android 进程内部的消息机制
- windows窗口消息内部处理机制
- Storm内部的消息传递机制
- Flex经验谈---用事件模拟一个Flex内部消息机制
- 服务器内部模块间的消息通知机制
- Netty实现消息推送以及内部心跳机制
- Netty实现消息推送以及内部心跳机制
- Handler 消息处理机制 简单语法介绍(内部)
- WPF的消息机制(二)- WPF内部的5个窗口之隐藏消息窗口
- 消息机制
- 消息机制
- 消息机制
- 消息机制
- 消息机制
- WINDOWS核心编程——异常处理
- CSS动画详解
- 可以在保利威视后台查看自己开发CMS系统帐号看了某个视频多长时间
- java生成二维码
- MYSQL时间函数
- Unity_内部消息机制
- 剑指Offer----从上往下打印二叉树
- memcpy和memmove的区别
- 高动态范围(HDR)渲染——最新中文手册
- MessageFormat.format和url带有特殊
- hihocoder 1523 : 数组重排2
- 理解linux虚拟文件系统VFS
- linux下用cron定时执行任务的方法
- HDU2567 寻梦【输入输出流】