unity中EasyTouch插件的基本使用

1关于EasyTouch的两种写法
在4.x版本中,需要在Hierarchy中创建EasyTouch,在5版本中不需要,建议都创建。
①4.x版本:

using System.Collections;
using System.Collections.Generic;
using HedgehogTeam.EasyTouch;
using UnityEngine;
public class ESTCTset : MonoBehaviour {
    private void OnEnable () {
        EasyTouch.On_TouchStart += OnTouchStart;
        EasyTouch.On_TouchUp += OnTouchEnd;
        EasyTouch.On_Swipe += OnSwipe;
    }ipe -= OnSwipe;
    }

    private void OnDisable () {
        EasyTouch.On_TouchStart -= OnTouchStart;
        EasyTouch.On_TouchUp -= OnTouchEnd;
        EasyTouch.On_Sw
    private void OnDestroy () {
        EasyTouch.On_TouchStart -= OnTouchStart;
        EasyTouch.On_TouchUp -= OnTouchEnd;
        EasyTouch.On_Swipe -= OnSwipe;
    }
    void OnTouchStart (Gesture gesture) {
        Debug.Log ("OnTouchStart");
        Debug.Log ("ActionTime" + gesture.startPosition);

    }
    void OnTouchEnd (Gesture gesture) {
        Debug.Log ("OnTouchEnd");
        Debug.Log ("ActionTime" + gesture.actionTime);
    }
    void OnSwipe (Gesture gesture) {
        Debug.Log ("OnSwipe");
        Debug.Log ("Type" + gesture.swipe);
    }
}

②5版本

using System.Collections;
using System.Collections.Generic;
using HedgehogTeam.EasyTouch;
using UnityEngine;

public class ESTC5 : MonoBehaviour {
    // Start is called before the first frame update
    void Start () {

    }

    // Update is called once per frame
    void Update () {
        Gesture currentGesture = EasyTouch.current;
        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) {
        Debug.Log ("OnTouchStart");
        Debug.Log ("ActionTime" + gesture.startPosition);

    }
    void OnTouchEnd (Gesture gesture) {
        Debug.Log ("OnTouchEnd");
        Debug.Log ("ActionTime" + gesture.actionTime);
    }
    void OnSwipe (Gesture gesture) {
        Debug.Log ("OnSwipe");
        Debug.Log ("Type" + gesture.swipe);
    }
}

2注意ctrl,alt对双指的模仿

3关于quick gesture,如果有allow over me这种类似选项
如pinch(缩放)中以一个属性是gesture over me,如果勾选这个必须有碰撞器,不然无法检测到手指是否在物体上,而不勾选,则可以正常使用,因为不需要去检测是否碰触到。

4注意quick gesture中pinch和twist如果同时存在且都要触发end事件,这两个会冲突
该插件作者的解决方式:通过逻辑需要来切换
EasyTouch.SetEnablePinch(true);
EasyTouch.SetEnableTwist(false);

5关于EasyTouch inspector的属性
①unity remote:是一个远程调试功能,通过下载手机app,用数据线和pc相连,方便我们在pc上调试。

②:gui compatibility(ui电容性:如果勾选,easytouch就不响应在ugui上的事件(除了On_OverUIElement这个事件),就全权由ugui负责, 如果不勾选,就可以响应EasyTouch。
③:enable Unity deteciton:是否允许UI检测,如果不勾选,他就会忽略UI层,穿透它去拾取Ui后面的东西。

枚举类型:
EasyTouch.GesturePriority:手势优先值
EasyTouch.SwipeDirection:手势滑动方向
6EasyTouch事件
On_Cancel:当系统无法追踪到手指,就是手指离开屏幕会调用这个事件。
On_Cancel2Fingers:当双指手势时,有一个手指离开时会调用

EasyTouch对层处理:
LayerMask mask = EasyTouch.Get3DPickableLayer();
EasyTouch.Set3DPickableLayer(mask);

多摄像机处理:
EasyTouch.AddCamera(cam,false);第二个参数的意思是是不是ugui的渲染相机,false即不是

Gesture gesture;
gesture.fingerIndex:第一个手指为0,第二个为1,如果为-1表示当前是双指操作
Gesture.GetTouchToWorldPoint(vector3 position);既可以显示目标当前世界坐标的位置,也可以计算这个点到摄像机的长度

扫描二维码关注公众号,回复: 10354869 查看本文章
发布了4 篇原创文章 · 获赞 1 · 访问量 1328

猜你喜欢

转载自blog.csdn.net/obf2018/article/details/105234502