总结:
这里面的一些功能,就可以拿来做移动或者PC的很多功能了,这是一个很有用的插件。
禁用0618错误
EasyTouch4_x的写法:
using HedgehogTeam.EasyTouch;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 有订阅方法,在不用的时候一定要取消订阅
/// </summary>
public class EasyTouch4_x : MonoBehaviour
{
//在OnEnable中订阅EasyTouch的事件
private void OnEnable()
{
EasyTouch.On_TouchStart += OnTouchStart;
EasyTouch.On_TouchUp += OnTouchEnd;
EasyTouch.On_Swipe += OnSwipe;
}
//在OnDisable与OnDestroy中取消订阅OnEnable中对应的事件
private void OnDisable()
{
EasyTouch.On_TouchStart -= OnTouchStart;
EasyTouch.On_TouchUp -= OnTouchEnd;
EasyTouch.On_Swipe -= OnSwipe;
}
private void OnDestroy()
{
EasyTouch.On_TouchStart -= OnTouchStart;
EasyTouch.On_TouchUp -= OnTouchEnd;
EasyTouch.On_Swipe -= OnSwipe;
}
void OnTouchStart(Gesture gesture)//必须包含这个参数Gesture gesture
{
Debug.Log("OnTouchStart");
Debug.Log("StartPosition" + gesture.startPosition);
}
void OnTouchEnd(Gesture gesture)
{
Debug.Log("OnTouchEnd");
Debug.Log("ActionTime" + gesture.actionTime);
}
void OnSwipe(Gesture gesture)
{
Debug.Log("Swip");
Debug.Log("Type" + gesture.touchType);
}
}
EasyTouch5_x的新写法:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HedgehogTeam.EasyTouch;
public class EasyTouch5_x : MonoBehaviour {
//EasyTouch5.x版本中的新特性可以不用书写订阅事件等一套语句
private void Update()
{
//通过currentGesture获取当前玩家输入的手势
Gesture currentGesture = EasyTouch.current;
//当前手势等于这个则执行
//currentGesture != null是为了防止一开始没有输入时报空指针
if (currentGesture != null&& EasyTouch.EvtType.On_TouchStart==currentGesture.type)
{
OnTouchStart(currentGesture);
}
if (currentGesture != null && EasyTouch.EvtType.On_TouchUp == currentGesture.type)
{
OnTouchEnd(currentGesture);
}
if (currentGesture != null && EasyTouch.EvtType.On_Swipe == currentGesture.type)
{
OnSwipe(currentGesture);
}
}
void OnTouchStart(Gesture gesture)//必须包含这个参数Gesture gesture
{
Debug.Log("OnTouchStart");
Debug.Log("StartPosition" + gesture.startPosition);
}
void OnTouchEnd(Gesture gesture)
{
Debug.Log("OnTouchEnd");
Debug.Log("ActionTime" + gesture.actionTime);
}
void OnSwipe(Gesture gesture)
{
Debug.Log("Swip");
Debug.Log("Type" + gesture.touchType);
}
}
QuickGestureDemo
有这几个操作:
缩放Pinch
这个需要勾选
5.0的新特性:EasyTouchTrigger