位置: 编程技术 - 正文

A Type-Safe Event System for Unity3D

发布时间:2024-02-27

推荐整理分享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带位置图标的拖动例子

  • 一般纳税人的计税方式是什么
  • 应税销售收入是指什么
  • 递延所得税负债转回怎么理解
  • 运输公司税率和税种
  • 预计负债的会计核算
  • 金税盘购买的会计分录
  • 预付账款长期挂账风险
  • 公司购买汽车的购置税怎么做账
  • 预收账款借方余额可以计入应收账款的哪方
  • 内部报送会计信息有哪些
  • 房产评估费会计分录
  • 酒店筹建是什么意思
  • 收到费用怎么写分录
  • 持有营业执照
  • 取得增值税专用发票是否可以抵扣
  • 少数股东损益借方增加还是贷方增加
  • 购入材料的应付账款包括商业折扣吗
  • 出纳汇错款会计怎么做账
  • 营业成本主要包括
  • 借主营业务成本贷库存商品
  • 价外收入是什么意思
  • 地铁充值发票能报销吗
  • 预付的各种押金
  • 临时设施是租入还是租入
  • 如何设置让电脑运行更快
  • linux gcc命令详解
  • 借方为什么要转账
  • php设计思路
  • 会计学中的折旧是什么意思
  • 核定征收的企业所得税怎么算
  • 生产企业可以抵扣进项税的
  • 调频连续波雷达
  • 数学建模三个人谁最难
  • 强制缓存与协商缓存的区别
  • 一次开票分期确认怎么弄
  • 广告系统源码
  • 企业的研发支出
  • python中insert函数怎么用
  • 织梦前台的菜单怎么换
  • 建筑总承包分包单位可以是市政总承包吗
  • 陈列费怎么开票
  • 土地增值税采用
  • 实收资本报表怎么填
  • 发票入账是什么意思
  • 成品油企业开具电票前还需要先进行库存下载吗
  • 预付账款的账务处理视频教程
  • 办理产权证费用明细
  • 到银行提取备用金
  • 收到投资款如何声明
  • 如何核算购进商品
  • 高速过路费发票图片
  • 股权转让如何办理
  • 电商刷单的成本如何处理?
  • 坏账准备确认坏账
  • 企业缴纳社保费包括企业部分和个人部分
  • 我是小规模纳税人,客户都想获得13%的专票
  • 餐厅的租金是多少钱一个月
  • 个税手续费返还奖励财务人员的文件
  • 什么是预收账款的正常余额
  • 开支票如何做账
  • 企业建帐的基本要求
  • linux中vi编辑器怎么使用
  • win10快速启动怎么进入bios
  • 如何解决笔记本电脑温度过高 蓝屏
  • mac电脑打开safari
  • linux系统基础教程
  • linux windows转linux
  • [置顶] 关于UNITY5.0和高通AR4.2.3在手机上白屏的问题
  • 新闻客户端手机版下载
  • android开发环境安装步骤
  • css全局声明
  • nodejs搭建本地资源服务器
  • 详解金球奖之争
  • 简单阐述javascript的主要作用
  • 上海2023年个人所得税计算
  • 增值税纳税申报时间
  • 陕西国家税务
  • 怎样理解句子我还没弄清楚是怎么回事
  • 定期定额发票使用流程
  • 小学语文教学的核心素养
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号