位置: 编程技术 - 正文

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

  • 离岸价的含义
  • 学生兼职怎么交个人所得税吗
  • 个人出租如何交税
  • 企业所得税季度申报
  • 递延收益的核算
  • 未抵扣的进项发票是什么意思
  • 支付外国公司费用要交税吗
  • 出口企业类别在哪里查
  • 个税缴款三方协议
  • 广告制作赚钱吗?
  • 金融服务费进项可以抵扣吗
  • 发票不在业务发生地
  • 非居民工资薪金个人所得税计算方法
  • 企业现金管理办法
  • 公司代收代付会被监控吗
  • 房地产增值税发票有什么用
  • 私车公用产生的过路费怎么开发票
  • 待摊费用跨年冲销如何入账?
  • 补税款的分录应该怎么写
  • 营改增后应付职工薪酬如何核算个人所得税?
  • 电子发票开错了怎么解决?
  • 相互调转总分公司的原料物资 是视同销售吗?
  • 企业所得税地方分成比例
  • 苹果手机电池低于多少需要更换
  • 上月暂估入账的原材料的发票已经送到财务部
  • 社保增加人员网上申报
  • 隐藏登录界面的软件
  • uniapp vuecli
  • 购买专利权的会议纪要
  • 360路由器怎么连接网络
  • 自身权益工具有哪些
  • php去除字符串中的引号
  • php json格式化
  • php数组查询
  • 红字怎么看
  • 谷歌插件下载网址
  • 账本过次页的视频
  • 安装elipse教程
  • 编译和链接的区别是什么
  • zabbix 执行命令
  • xi:xtreg命令
  • 中国传统节日大概有多少
  • 网络销售税率怎么算
  • 10万以下销售额怎么算
  • 购买礼品的会计怎么做账
  • 电子商务公司怎么做账比较合适
  • dedecms51
  • 蔬菜开发票到哪里开呢?
  • sql server 2005 service pack3
  • 营业收入的构成分析应该从哪些方面进行?
  • 小企业会计准则2023电子版
  • 如何完成资产负债表
  • 无票收入会计分录实例
  • 路桥费税率是几个点
  • 材料会计的内容
  • 可抵扣进项税额的六种类型
  • 收到专利权投资的票据
  • 一般纳税人在外地预缴税款,预缴多了需不需退税
  • 备用金取多少钱会被监控
  • mysql详细介绍
  • MySQL 5.6 中TIMESTAMP with implicit DEFAULT value is deprecated错误
  • mysql字段什么意思
  • windows xp怎么打开
  • win8恢复出厂设置方法
  • windowsxp停止服务的时间
  • mac如何访问win10文件
  • linux dd测试
  • win8打开ie
  • win10 20h2 v2
  • centos6启动服务的命令
  • mmc.exe是什么
  • win8怎么添加wifi
  • win10更新需要重启怎么办
  • linux中tail命令详解
  • linux怎么cd
  • android获取音频信息
  • linearlayout布局怎么设置
  • Android的事件处理机制是一种______机制
  • 浅析2种JavaScript继承方式
  • 火药概念股有哪些
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设