77 lines
2.3 KiB
C#
77 lines
2.3 KiB
C#
using System;
|
|
using TG_TouchGesture;
|
|
using UnityEngine;
|
|
|
|
namespace LE_LevelEditor.LEInput
|
|
{
|
|
public class LE_InputDeviceTouchscreen : LE_InputDeviceBase
|
|
{
|
|
private const float ZOOM_SENSITIVITY = 1500f;
|
|
|
|
private int m_lastCursorActivationFrame = -100;
|
|
|
|
public LE_InputDeviceTouchscreen(LE_IInputHandler p_inputHandler)
|
|
: base(p_inputHandler)
|
|
{
|
|
TG_TouchGestures.Instance.EnableGesture(TG_ETouchGestureType.PRESS_1_FINGER);
|
|
TG_TouchGestures.Instance.EnableGesture(TG_ETouchGestureType.PRESS_2_FINGER);
|
|
TG_TouchGestures.Instance.EnableGesture(TG_ETouchGestureType.PRESS_3_FINGER);
|
|
TG_TouchGestures.Instance.EnableGesture(TG_ETouchGestureType.ZOOM);
|
|
TG_TouchGestures instance = TG_TouchGestures.Instance;
|
|
instance.OnGestureDetected = (EventHandler<TG_TouchGestureEventArgs>)Delegate.Combine(instance.OnGestureDetected, new EventHandler<TG_TouchGestureEventArgs>(OnTouchGestureDetected));
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
if (m_lastCursorActivationFrame != Time.frameCount)
|
|
{
|
|
m_inputHandler.SetIsCursorAction(false);
|
|
}
|
|
}
|
|
|
|
public override void Destroy()
|
|
{
|
|
if (TG_TouchGestures.IsInstanceSet)
|
|
{
|
|
TG_TouchGestures instance = TG_TouchGestures.Instance;
|
|
instance.OnGestureDetected = (EventHandler<TG_TouchGestureEventArgs>)Delegate.Remove(instance.OnGestureDetected, new EventHandler<TG_TouchGestureEventArgs>(OnTouchGestureDetected));
|
|
}
|
|
}
|
|
|
|
private void OnTouchGestureDetected(object p_object, TG_TouchGestureEventArgs p_args)
|
|
{
|
|
switch (p_args.Type)
|
|
{
|
|
case TG_ETouchGestureType.PRESS_1_FINGER:
|
|
{
|
|
Vector2 position3 = p_args.Position;
|
|
m_inputHandler.SetCursorPosition(new Vector3(position3.x, position3.y, 0f));
|
|
m_inputHandler.SetIsCursorAction(true);
|
|
m_lastCursorActivationFrame = Time.frameCount;
|
|
break;
|
|
}
|
|
case TG_ETouchGestureType.PRESS_2_FINGER:
|
|
{
|
|
Vector2 position2 = p_args.Position;
|
|
Vector2 delta2 = p_args.Delta;
|
|
m_inputHandler.RotateCamera(position2, position2 + delta2);
|
|
break;
|
|
}
|
|
case TG_ETouchGestureType.PRESS_3_FINGER:
|
|
{
|
|
Vector2 position = p_args.Position;
|
|
Vector2 delta = p_args.Delta;
|
|
m_inputHandler.MoveCamera(position, position - delta);
|
|
break;
|
|
}
|
|
case TG_ETouchGestureType.ZOOM:
|
|
{
|
|
float x = p_args.Delta.x;
|
|
m_inputHandler.MoveCamera(Vector3.zero, Vector3.forward * x * 1500f);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|