zoukankan      html  css  js  c++  java
  • 虚拟摇杆的修改

        上次的代码运行时会有bug:报错 ArgumentException: Index out of bounds. 即Input.GetTouch()函数进行了越界访问。于是上网看了看,发现Touch的机制是这样的:

    在四手指同触摸时,如果撤掉第二根手指,再按下去,会发生:

    touch[0]    fingerId=0                                    touch[0]    fingerId=0                            touch[0]    fingerId=0 

    touch[1]    fingerId=1    →            touch[1]    fingerId=2        →      touch[1]    fingerId=1

    touch[2]    fingerId=2                                   touch[2]    fingerId=3                             touch[2]    fingerId=2

    touch[3]    fingerId=3                                                                                                 touch[3]    fingerId=3 

    因此不能用fingerID来GetTouch。

        我先想的是,在按下时用一个int变量记录当时的Touches.Length,然后在GetTouch时判断一个3目运算符,像这样:

    1 Input.GetTouch(eventData.pointerId-
    2             (_oldTouchCount > Input.touches.Length ? _oldTouchCount - Input.touches.Length : 0))

        但是又想到,如果 0 1 2 3 4 五根手指 ,去掉1 3后,这样算的话2就不对了,最终还是采用了一个不怎么雅观,但是比较稳的办法:

     1     //通过fingerId获取其当前index
     2     private int GetTouchIndex(int fingerID)
     3     {
     4         for (int i = 0;i < Input.touches.Length; i++)
     5         {
     6             if (Input.GetTouch(i).fingerId == fingerID)
     7                 return i;
     8         }
     9         return -1;
    10     }

    这下怎么试都没问题了。

  • 相关阅读:
    Windows XP下Qemu模拟器上OpenSolaris的安置
    图解SMC下Solaris用户图形经管(下)
    Solaris 10的功能
    在Solaris 下用DVD光盘保存数据(1)
    Solaris10下载、安设和设置装备摆设(2)
    Solaris 10密码忘记打点法子
    对Unix任事器进行性能监测(上)
    Solaris效力打点东西 SMF快速入门指南(3)
    Solaris 10主动安顿DVD运用步骤
    Solaris效劳经管器材 SMF疾速入门指南(2)
  • 原文地址:https://www.cnblogs.com/charsoul/p/8711028.html
Copyright © 2011-2022 走看看