53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace TG_TouchGesture
|
|
{
|
|
public class TG_TouchGestureZoom : TG_TouchGestureBase
|
|
{
|
|
private const float MIN_RELATIVE_ZOOM_THRESHOLD = 0.1f;
|
|
|
|
private float m_lastZoomDist = -1f;
|
|
|
|
private bool m_isZooming;
|
|
|
|
public TG_TouchGestureZoom()
|
|
: base(TG_ETouchGestureType.ZOOM)
|
|
{
|
|
}
|
|
|
|
public override TG_TouchGestureEventArgs Update()
|
|
{
|
|
if (Input.touchCount == 2)
|
|
{
|
|
Touch[] touches = Input.touches;
|
|
float magnitude = (touches[1].position - touches[0].position).magnitude;
|
|
if (m_lastZoomDist == -1f)
|
|
{
|
|
m_lastZoomDist = magnitude;
|
|
}
|
|
else
|
|
{
|
|
float num = Mathf.Min(Screen.width, Screen.height);
|
|
if (Mathf.Abs(magnitude - m_lastZoomDist) / num > 0.1f || m_isZooming)
|
|
{
|
|
if (m_isZooming)
|
|
{
|
|
float num2 = (magnitude - m_lastZoomDist) / num;
|
|
m_lastZoomDist = magnitude;
|
|
return new TG_TouchGestureEventArgs(base.Type, GetTouchesCenterPosition(), Vector2.one * num2);
|
|
}
|
|
m_isZooming = true;
|
|
m_lastZoomDist = magnitude;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
m_lastZoomDist = -1f;
|
|
m_isZooming = false;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|