// Update is called once per frame public static void Update() { touches.RemoveAll( _ => ( ( _.Phase == TouchPhase.Ended ) || ( _.Phase == TouchPhase.Canceled ) || _.NoResponseCount > 10 ) ); for ( int i = 0; i < touches.Count; ++i ) { ++touches[ i ].NoResponseCount; } #if UNITY_EDITOR for ( int i = 0; i < 3; ++i ) { if ( UnityEngine.Input.GetMouseButtonDown( i ) == true ) { TouchData new_touch = new TouchData( MOUSE_FINGER_ID - i, UnityEngine.Input.mousePosition ); touches.Add( new_touch ); EventTouchBegan.Invoke( new_touch ); continue; } if ( UnityEngine.Input.GetMouseButton( i ) == true ) { var touch_data = touches.Find( _ => _.FingerId == MOUSE_FINGER_ID - i ); if ( touch_data != null ) { touch_data.Position = UnityEngine.Input.mousePosition; touch_data.NoResponseCount = 0; if ( touch_data.DeltaPosition == Vector2.zero ) { touch_data.Phase = TouchPhase.Stationary; EventTouchStationary.Invoke( touch_data ); } else { touch_data.Phase = TouchPhase.Moved; EventTouchMoved.Invoke( touch_data ); } continue; } } if ( UnityEngine.Input.GetMouseButtonUp( i ) == true ) { var touch_data = touches.Find( _ => _.FingerId == MOUSE_FINGER_ID - i ); if ( touch_data != null ) { touch_data.Position = UnityEngine.Input.mousePosition; touch_data.NoResponseCount = 0; touch_data.Phase = TouchPhase.Ended; EventTouchEnd.Invoke( touch_data ); continue; } } } #else var touches = UnityEngine.Input.touches; for ( int i = 0; i < touches.Length; ++i ) { switch ( touches[ i ].phase ) { case TouchPhase.Began: TouchData new_touch = new TouchData( touches[ i ] ); touches.Add( new_touch ); break; case TouchPhase.Moved: case TouchPhase.Stationary: var touch_data = touches.Find( _ => _.FingerId == touches[ i ].fingerId ); if ( touch_data != null ) { touch_data.NoResponseCount = 0; touch_data.Position = touches[ i ].position; touch_data.Phase = touches[ i ].phase; } else { // TouchPhase.Beganがこないままこのフェイズがくるときがある。 TouchData new_touch = new TouchData( touches[ i ] ); touches.Add( new_touch ); } break; case TouchPhase.Ended: case TouchPhase.Canceled: var touch_data = touches.Find( _ => _.FingerId == touches[ i ].fingerId ); if ( touch_data != null ) { touch_data.NoResponseCount = 0; touch_data.Position = touches[ i ].position; touch_data.Phase = touches[ i ].phase; } break; } } #endif }