
作用:触摸控制器
链接:https://pan.baidu.com/s/18LLWN7E6rysoGZqwmqtnxA 密码:aiyl
EasyTouchBundle
| — EasyTouch 触摸检测
| — | — Documentation 文档
| — | — Examples 例子
| — | — Plugins 插件
| — EasyTouchControls 控制
| — | — Component 组成部分
| — | — Documentation 文档
| — | — Examples 例子
| — | — Plugins 插件
| — | — Prefab 预制体
| — Install安装
| — | — PlayMakerAddOn
双击错误,打开错误的文件
加上:
#pragma warning disable 0618
EventType.mouseDown修改为:EventType.MouseDown
using HedgehogTeam.EasyTouch;
右键创建一个GameObject物体 — EasyTouch — EasyTouch
右键创建一个GameObject空物体 — 命名为EasyTouchManager
在 EasyTouchManager 上加C#代码 — EasyTouchManager5_Demo.cs
2个方法,方法一比较随便,方法二更专业,哈哈哈
方法一:
using System.Collections;using System.Collections.Generic;using UnityEngine;using HedgehogTeam.EasyTouch;//1、导入类/// <summary>/// 五代EasyTouch特性 使用的是 单例 来 监听事件/// </summary>public class EasyTouchManager5_Demo : MonoBehaviour{void Update()//2、update这个方法{Gesture currentGesture = EasyTouch.current;//3、获取当前手势if (currentGesture == null) return;//4、注意 当手机屏幕上没有任何操作的时候currentGesture是null的,要添加一个判断,防止空指针异常//5、以下是事件监听//按下if (EasyTouch.EvtType.On_TouchStart == currentGesture.type){//可以把方法写在里面print("OnTouchStart");print("StartPosition" + currentGesture.startPosition);//触摸位置}//抬起if (EasyTouch.EvtType.On_TouchUp == currentGesture.type){//可以把方法写在里面print("OnTouchEnd");print("OnTouchEnd" + gesture.actionTime);//触摸时间}//滑动if (EasyTouch.EvtType.On_Swipe == currentGesture.type){//可以把方法写在里面print("OnSwipe");print("Type" + gesture.type);//触摸类型}}}
方法二:
using System.Collections;using System.Collections.Generic;using UnityEngine;using HedgehogTeam.EasyTouch;//1、导入类/// <summary>/// 五代EasyTouch特性 使用的是 单例 来 监听事件/// </summary>public class EasyTouchManager5_Demo : MonoBehaviour{void Update()//2、update这个方法{Gesture currentGesture = EasyTouch.current;//3、获取当前手势if (currentGesture == null) return;//4、注意 当手机屏幕上没有任何操作的时候currentGesture是null的,要添加一个判断,防止空指针异常//5、以下是事件监听//按下if (EasyTouch.EvtType.On_TouchStart == currentGesture.type){OnTouchStart(currentGesture);}//抬起if (EasyTouch.EvtType.On_TouchUp == currentGesture.type){OnTouchEnd(currentGesture);}//滑动if (EasyTouch.EvtType.On_Swipe == currentGesture.type){OnSwipe(currentGesture);}}void OnTouchStart(Gesture gesture){//可以把方法写在里面print("OnTouchStart");print("StartPosition" + gesture.startPosition);//触摸位置}void OnTouchEnd(Gesture gesture){//可以把方法写在里面print("OnTouchEnd");print("OnTouchEnd" + gesture.actionTime);//触摸时间}void OnSwipe(Gesture gesture){//可以把方法写在里面print("OnSwipe");print("Type" + gesture.type);//触摸类型}}