找回密码
 立即注册
查看: 6570|回复: 65

Unity3D在iphone上的多点触摸应用

[复制链接]
发表于 2012-12-15 19:42 | 显示全部楼层 |阅读模式

老外的研究例子,本来有一段flash视频,好像地址失效了,就不放上来了。
检测iphone手机多点触摸脚本,带源码

There are a lot of questions on the Unity forums about how to handle multi-touch on iPhone. We’ve done a few experiments with multi-touch–although nothing in a game yet–but here’s one solution. This had a few goals:

Avoid iPhoneTouchPhase, which is unreliable (particularly with the remote)
Abstract touch tracking logic from game logic
Use a minimal amount of code
Multi-Touch Example (Unity iPhone) from Matthew Wegner on Vimeo.

This solution breaks the problem up into two classes, a Tracker and a Manager.  The core of the manager uses a Hashtable to tie tracker objects to their finger IDs.  The logic looks like:

Reset all trackers to “clean” state
Loop through all touch events
If we don’t have a tracker for this finger ID, create one (and assume touch has started)
If we already have a tracker object for this finger ID, tell it to update
Mark tracker as dirty
Any trackers that are still marked clean are assumed to be ended
There is some logic separation here, although it isn’t as clean as it could be.  The code that’s spawning/moving cubes is placed directly into the TouchTracker class.  In production we would strive to split this up, so the grunt work of tracking touches is totally separate from any game logic.  You could have your game logic get notifications of new/ended touches, or you could subclass TouchTracker and set up functions like OnTouchStarted, OnTouchEnded, and OnTouchUpdated.  Unity presents a lot of options for situations like this.

Enjoy the example, and comment if you make any changes or improvements.  This is far from perfect, but I think it’s a good direction to take.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
发表于 2017-3-2 20:26 | 显示全部楼层
很不错
发表于 2017-3-2 19:34 | 显示全部楼层
好帖就是要顶
发表于 2017-3-2 20:04 | 显示全部楼层
顶顶多好
发表于 2017-3-2 19:49 | 显示全部楼层
难得一见的好帖
发表于 2017-3-2 20:27 | 显示全部楼层
很好哦
发表于 2017-3-19 17:58 | 显示全部楼层
很不错
发表于 2017-3-19 17:36 | 显示全部楼层
真心顶
发表于 2017-3-19 18:17 | 显示全部楼层
难得一见的好帖
发表于 2017-3-19 18:22 | 显示全部楼层
不错不错
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-13 09:23 , Processed in 0.173564 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表