using UnityEngine; namespace TG_TouchGesture { public class TG_TouchGestureTap : TG_TouchGestureBase { private const float MAX_TOUCH_TIME_FOR_TAP = 1f; private const float MAX_DISTANCE_FOR_TAP = 0.1f; private int m_framesNoTouch; private bool m_isTapDown; private float m_tapStartTime; private Vector2 m_tapPos = Vector3.zero; public TG_TouchGestureTap() : base(TG_ETouchGestureType.TAP) { } public override TG_TouchGestureEventArgs Update() { if (m_isTapDown) { if (Input.touchCount == 0) { m_framesNoTouch++; m_isTapDown = false; return new TG_TouchGestureEventArgs(base.Type, m_tapPos); } if (Input.touchCount != 1 || Time.realtimeSinceStartup - m_tapStartTime > 1f || (Input.touches[0].position - m_tapPos).magnitude > 0.1f) { m_framesNoTouch = 0; m_isTapDown = false; } } else if (Input.touchCount == 0) { m_framesNoTouch++; m_isTapDown = false; } else if (Input.touchCount == 1) { if (m_framesNoTouch > 1) { m_isTapDown = true; m_tapStartTime = Time.realtimeSinceStartup; m_tapPos = Input.touches[0].position; } m_framesNoTouch = 0; } else { m_framesNoTouch = 0; m_isTapDown = false; } return null; } } }