72 lines
1.8 KiB
C#
72 lines
1.8 KiB
C#
using UnityEngine;
|
|
|
|
namespace TG_TouchGesture
|
|
{
|
|
public class TG_TouchGesturePress : TG_TouchGestureBase
|
|
{
|
|
private int m_fingerCount;
|
|
|
|
private float m_minTouchTimeBeforeDetection;
|
|
|
|
private bool m_isTapDown;
|
|
|
|
private float m_tapStartTime;
|
|
|
|
private Vector2 m_initialCenterPosition = Vector2.zero;
|
|
|
|
private Vector2 m_lastCenterPosition = Vector2.zero;
|
|
|
|
private bool m_isWaitingForNoTap;
|
|
|
|
public TG_TouchGesturePress(TG_ETouchGestureType p_type, int p_fingerCount, float p_minTouchTimeBeforeDetection)
|
|
: base(p_type)
|
|
{
|
|
m_fingerCount = p_fingerCount;
|
|
m_minTouchTimeBeforeDetection = p_minTouchTimeBeforeDetection;
|
|
}
|
|
|
|
public override TG_TouchGestureEventArgs Update()
|
|
{
|
|
if (m_isTapDown)
|
|
{
|
|
if (Input.touchCount != m_fingerCount)
|
|
{
|
|
m_isWaitingForNoTap = true;
|
|
m_isTapDown = false;
|
|
}
|
|
else if (Time.realtimeSinceStartup - m_tapStartTime > m_minTouchTimeBeforeDetection)
|
|
{
|
|
m_isWaitingForNoTap = false;
|
|
Vector2 touchesCenterPosition = GetTouchesCenterPosition();
|
|
Vector2 p_delta = touchesCenterPosition - m_lastCenterPosition;
|
|
m_lastCenterPosition = touchesCenterPosition;
|
|
return new TG_TouchGestureEventArgs(base.Type, m_initialCenterPosition, touchesCenterPosition, p_delta);
|
|
}
|
|
}
|
|
else if (Input.touchCount == m_fingerCount)
|
|
{
|
|
if (!m_isWaitingForNoTap)
|
|
{
|
|
m_isTapDown = true;
|
|
m_tapStartTime = Time.realtimeSinceStartup;
|
|
m_lastCenterPosition = GetTouchesCenterPosition();
|
|
m_initialCenterPosition = new Vector2(m_lastCenterPosition.x, m_lastCenterPosition.y);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_isTapDown = false;
|
|
if (Input.touchCount > m_fingerCount)
|
|
{
|
|
m_isWaitingForNoTap = true;
|
|
}
|
|
}
|
|
if (m_isWaitingForNoTap && Input.touchCount == 0)
|
|
{
|
|
m_isWaitingForNoTap = false;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|