位置: 编程技术 - 正文

A Type-Safe Event System for Unity3D

编辑:rootadmin

推荐整理分享A Type-Safe Event System for Unity3D,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

转载自: Event Listener pattern is an extremely common design pattern. Using Events instead of method calls let an object communicate with another object (or many objects) without explicit knowledge of the other object. With events acting as an implicit interface between objects, we can write much more loosely coupled (thus more reusable) code.

Unity’s own message passing system can be leveraged to achieve this effect, but there are a few problems with it. First, sending messages is hierarchy-dependent. You either need a reference to the object you wish to send the message (event) to, or you need a reference to that object’s parent object. This is not loosely coupled. Secondly, it’s not statically type-safe.

There have been several solutions to this problem (for example, FlashBang’s messaging system or this one on the UnifyCommunity wiki). These still lack type-safety, and won’t quite do.

Here is my event system implementation. It looks quite a bit like the event system in AS3:

A Type-Safe Event System for Unity3D

To use this thing, first we declare a GameEvent subclass. This event can carry with it all of the parameters needed by the objects listening for the event.

Registering to listen for the event looks like this:

And finally, to raise the event, do this:

The cool thing about this implementation is that it’s type-safe (listener registration errors will be caught at compile time, and no casting of events or event arguments) and it doesn’t require listening objects to implement a special interface or use Unity’s built-in message passing system.

The interface for this system is almost identical to that presented by Mike Mittleman at Unite , and I’d wager our implementations are similar. If you really want a rundown of the benefits and pitfalls of event-driven Unity development, I suggest watching his presentation on Unity’s website.

NGUI带位置图标的拖动例子 转载自:

Unity3D ugui事件监听机制 UGUI控件的事件响应有很多种方式,比如使用组件EventTrigger来添加事件监听,或者实现IDragHandler等接口,或者更直接地继承EventTrigger来进行更灵话的调用

Screen.sleepTimeout=SleepTimeOut.NeverSleep 禁止屏幕锁屏 Screen.

标签: A Type-Safe Event System for Unity3D

本文链接地址:https://www.jiuchutong.com/biancheng/369340.html 转载请保留说明!

上一篇:UGUI 实现Button长按效果(RepeatButton)(ugui scrollview)

下一篇:NGUI带位置图标的拖动例子

  • 融资租赁和经营租赁的特点
  • 应纳税所得额为什么要减去国债利息收入
  • 计提应收的增值税返还
  • 小规模纳税人不允许开具零税率发票
  • 一般纳税人转让二手车增值税税率
  • 未提供一般纳税人证明
  • 哪些项目容易漏缴个人所得税
  • 固定资产明细表范本
  • 印花税没有计提直接付了怎么做账
  • 食堂收支情况
  • 实收资本印花税税率多少
  • 公司过桥贷款怎么贷
  • 金税盘技术服务费可以全额抵扣吗
  • 销售旧货时的售后是什么
  • 业务宣传及广告费超比例
  • 存货的主要内容包括什么
  • 从境外取得的佣金
  • 固定资产赔偿制度
  • 小规模企业所得税税率多少
  • 协议报价税率与开出的发票不一致怎么办?
  • 增值税普通发票需要交税吗
  • 农业企业销售林木是否要交印花税?
  • 一般纳税人施工安装税点
  • 个人所得税成本费用包括哪些
  • 电子公章盖上去怎么文字看不到了
  • 培训学校的收入
  • 小规模企业交纳印花税吗
  • 鸿蒙3.0平板适配名单
  • 玩游戏网络延时高怎么处理
  • 收到负数发票怎么办
  • 公司个人垫付的费用会计分录
  • uefiu盘安装系统步骤win10
  • amr文件什么意思
  • 制造费用主要包括哪些费用
  • php canal
  • php找出字符串中出现最多的字母
  • php读取txt文件内容
  • 环境保护税的征税范围及计税依据
  • Vue Admin Template关闭eslint校验,lintOnSave:false设置无效解决办法
  • 金税盘如何使用流程
  • 小微企业免教育附加
  • vue在项目中怎么用的
  • php date()
  • 优先股可转让吗
  • 企业销售旧固定资产税票开票
  • 应交税金科目应不应该有余额
  • photoshop虚化局部
  • 帝国cms修改提示怎么设置
  • 员工洗衣机使用制度
  • 门诊收费票据能重新打印吗
  • 即征即退 条件
  • 多用途卡的监管机构是
  • 其他综合收益和营业外收入的区别
  • 收到分红的会计科目
  • 产品研发项目管理 系统 国外
  • 建筑企业怎么结算成本
  • 企业内在
  • mysql数据库迁移上云
  • win7系统的笔记本电脑有哪些
  • windows.h在linux中
  • win10手机版微信uwp下载
  • linux 如何查看
  • linux修改22端口号
  • linux小技巧
  • linux运行级别有几种
  • node.js jquery
  • cocos2d-x教程
  • nodejs后端教程
  • nodejs内置的包管理器
  • jquery获取元素css
  • 并行 python
  • unity?
  • jquery滚动条滚动到指定位置
  • JavaScript fontsize方法入门实例(按照指定的尺寸来显示字符串)
  • js编写一个标准的单例模式类
  • javascript面向对象吗
  • python 判断字符串编码
  • 完美实现碳排放自主抵消的工厂叫什么
  • 全面推进行政执法公示制度包含的主要内容有
  • 国税局可以办理什么业务
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设