纳金网

标题: unity3d在iphone上的多点触摸应用 [打印本页]

作者: 会飞的鱼    时间: 2011-12-21 15:03
标题: unity3d在iphone上的多点触摸应用
There are a lot of questions on the Unity f***ms 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

1.If we don’t have a tracker for this finger ID, create one (and assume touch has started)

2.If we already have a tracker object for this finger ID, tell it to update

3.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 ***nt 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.
由 uke 发表
作者: C.R.CAN    时间: 2012-3-11 23:24
好可爱的字,学习了

作者: 奇    时间: 2012-4-6 23:31
都闪开,介个帖子,偶来顶

作者: tc    时间: 2012-6-9 23:23
心中有爱,爱咋咋地

作者: 奇    时间: 2012-7-25 23:23
不会吧,太恐怖了

作者: tc    时间: 2012-8-18 00:12
佩服,好多阿 ,哈哈

作者: 奇    时间: 2012-8-30 00:55
你们都躲开,我来顶

作者: 菜刀吻电线    时间: 2012-9-24 23:18
有意思!学习了!

作者: 菜刀吻电线    时间: 2012-10-10 23:19
跑着去顶朋友滴铁

作者: 晃晃    时间: 2012-10-12 23:21
好铁多多发,感激分享

作者: 奇    时间: 2013-2-10 23:27
好铁多多发,感激分享

作者: 奇    时间: 2013-2-20 23:36
好可爱的字,学习了

作者: tc    时间: 2013-3-8 23:21
非常感谢,管理员设置了需要对新回复进行审核,您的帖子通过审核后将被显示出来,现在将转入主题





欢迎光临 纳金网 (http://old.narkii.com/club/) Powered by Discuz! X2.5