位置: 编程技术 - 正文

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带位置图标的拖动例子

  • 消费税基本特点?
  • 国家税收与地方税收
  • 起重机属于固定资产哪个类别
  • 房地产开发企业土地增值税预缴
  • 企业年报股东及出资信息要怎么填写
  • 小微企业印花税减免最新政策
  • 支付的工会经费现金流量项目是什么?
  • 物业公司收款一般多久
  • 出差怎么订机票
  • 公积金需要每月缴纳吗
  • 内账固定资产已经费用化了怎么办
  • 合伙做生意账目
  • 电信线路租用的手机
  • 未盖发票章怎么办
  • 石家庄国税发票查验平台
  • 红字发票开具只能针对一份发票 不可以只冲红其中一部分吗?
  • 哪些项目可以不报建
  • 公益组织接受捐赠怎么开票
  • 支付宝微信结算属于什么结算方式
  • 汽车维修发票是几个点
  • 会议费 报销
  • 利息支出的会计科目
  • win10windows资源管理器怎么打开
  • 华为系统设置权限
  • 银行承兑汇票和银行汇票的区别
  • 贷款本息转本金
  • php 多维数组转换成字符串
  • 域名停靠是病毒吗
  • 可以关闭系统的快捷键
  • 销售人员奖励办法
  • 输入字母和数字 小学信息技术课
  • 内资企业股权转让流程
  • 资源税纳税申报流程
  • 工会经费税前扣除标准2022
  • element组件的二次封装注册
  • laravel技巧
  • 寓意幸福和团圆的网名
  • AI:DeepSpeed Chat(一款帮用户训练自己模型的工具且简单/低成本/快 RLHF 训练类ChatGPT高质量大模型)的简介、安装、使用方法之详细攻略
  • php array_fill
  • 出口退税抵减应计入哪里
  • 企业向合伙企业转让股权
  • sqlserver正则表达式用法
  • 新会计准则下的资产负债表
  • 小规模纳税人免税怎么做账
  • 怎么在电子税务局查询进项发票
  • 公对私转账没有到账怎么查询
  • 公司什么项目
  • 个税清算所得税怎么计算
  • sql server 2008打开界面
  • 产业增加值是增长量吗
  • 房地产开发企业成本核算方法
  • 企业研发费用加计扣除比例
  • 公司注销前欠客户钱
  • 电商刷单返现如何做账务处理合适?
  • 个人独资企业进行委托管理要签订劳动合同
  • 企业委托企业
  • 核算费用
  • 服装厂布料都是在哪里进的
  • 收到投资款如何申报印花税
  • 被代持股份的股东需要负责吗
  • 仓储领域
  • 描述企业会计准则中对固定资产的具体规定
  • sql server批量导入数据
  • mysql数据库迁移方案
  • assoc.exe=exefile什么意思
  • xp桌面图标设置
  • 安装win7系统后无法引导启动
  • mac图片格式怎么转换jpeg
  • mysqld是什么进程
  • 电脑安装win8
  • nodejs模拟点击
  • c#的程序集
  • Node.js中的全局对象有
  • jquery model
  • linux shutdown命令详解
  • python中字符串的方法
  • python安装包的命令
  • 国家财政税务局
  • 什么叫税务备案
  • 云南省新农合网上缴费app
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设