Ejemplo n.º 1
0
 /// <summary>
 /// 1フレーム間のdeltaPositionを返す
 /// タッチしてから離すまでのdeltaを計算する場合は、Dictionary<int fingerId Vector3 sum>で毎フレーム加算すると良い
 /// </summary>
 /// <returns>The delta position</returns>
 /// <param name="i">touch index</param>
 public static Vector3 GetDeltaPosition(int i)
 {
     if (isEditor)
     {
         TouchInfo info = MultiPlatformTouchUtils.GetTouch(i);
         if (info != TouchInfo.None)
         {
             Vector3 currentPosition = Input.mousePosition;
             Vector3 delta           = currentPosition - PreviousPosition;
             PreviousPosition = currentPosition;
             return(delta);
         }
     }
     else
     {
         if (Input.touchCount >= i)
         {
             Touch touch = Input.GetTouch(i);
             PreviousPosition.x = touch.deltaPosition.x;
             PreviousPosition.y = touch.deltaPosition.y;
             return(PreviousPosition);
         }
     }
     return(Vector3.zero);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// FingerId毎に計算しているので、マルチタッチ対応
        /// タッチしてから離すまでのdeltaPosとdeltaTimeを計算
        /// </summary>
        protected void UpdateTouchCheck()
        {
            var touchCount = MultiPlatformTouchUtils.touchCount;

            if (touchCount > 0)
            {
                for (int i = 0; i < touchCount; i++)
                {
                    var fingerId = MultiPlatformTouchUtils.getFingerId(i);

                    switch (MultiPlatformTouchUtils.GetTouch(i))
                    {
                    case TouchInfo.Began:
                        // Mapの初期化
                        m_deltaPosSumMap[fingerId]  = Vector3.zero;
                        m_deltaTimeSumMap[fingerId] = 0.0f;


                        break;

                    case TouchInfo.Moved:
                        m_deltaPosSumMap[fingerId]  += MultiPlatformTouchUtils.GetDeltaPosition(i);
                        m_deltaTimeSumMap[fingerId] += MultiPlatformTouchUtils.GetDeltaTime(i);


                        break;

                    case TouchInfo.Ended:
                        m_deltaPosSumMap[fingerId]  += MultiPlatformTouchUtils.GetDeltaPosition(i);
                        m_deltaTimeSumMap[fingerId] += MultiPlatformTouchUtils.GetDeltaTime(i);

                        // 指を話した時の処理
                        ReleaseFinger(fingerId);
                        //

                        // Mapの削除
                        m_deltaPosSumMap.Remove(fingerId);
                        m_deltaTimeSumMap.Remove(fingerId);

                        break;

                    default:
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// タッチポジションを取得(エディタと実機を考慮)
 /// </summary>
 /// <returns>タッチポジション。タッチされていない場合は (0, 0, 0)</returns>
 public static Vector3 GetTouchPosition(int i)
 {
     if (isEditor)
     {
         TouchInfo touch = MultiPlatformTouchUtils.GetTouch(i);
         if (touch != TouchInfo.None)
         {
             PreviousPosition = Input.mousePosition;
             return(PreviousPosition);
         }
     }
     else
     {
         if (Input.touchCount >= i)
         {
             Touch touch = Input.GetTouch(i);
             TouchPosition.x = touch.position.x;
             TouchPosition.y = touch.position.y;
             return(TouchPosition);
         }
     }
     return(Vector3.zero);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 前回の呼び出しからのdeltaTimeを返します。(実機は1フレーム間)
 /// </summary>
 /// <returns>The delta time.</returns>
 /// <param name="i">The index.</param>
 public static float GetDeltaTime(int i)
 {
     if (isEditor)
     {
         TouchInfo info = MultiPlatformTouchUtils.GetTouch(i);
         if (info != TouchInfo.None)
         {
             float currentTime = Time.time;
             float deltaTime   = currentTime - PreviousTime;
             PreviousTime = currentTime;
             return(deltaTime);
         }
     }
     else
     {
         if (Input.touchCount >= i)
         {
             Touch touch     = Input.GetTouch(i);
             float deltaTime = touch.deltaTime;
             return(deltaTime);
         }
     }
     return(0.0f);
 }