[Unity]EasyTouch手指滑动返回距离值
Unity项目导入EasyTouch插件
Assets\EasyTouchBundle\EasyTouch\Examples\4.X\SimpleExamples文件夹内有手指示例场景
自己的代码写
...
using HedgehogTeam.EasyTouch;//EasyTouch
.../// <summary>/// 当组件 可用/// </summary>void OnEnable(){StartGame();}/// <summary>/// 当组件不可用/// </summary>void OnDestroy(){UnsubscribeEvent();}/// <summary>/// 当组件不可用/// </summary>void OnDisable(){UnsubscribeEvent();}/// <summary>/// 取消订阅事件 Unsubscribe to events/// </summary>void UnsubscribeEvent(){EasyTouch.On_SwipeEnd -= On_SwipeEnd;EasyTouch.On_TouchStart2Fingers -= On_TouchStart2Fingers;EasyTouch.On_PinchIn -= On_PinchIn;EasyTouch.On_PinchOut -= On_PinchOut;EasyTouch.On_PinchEnd -= On_PinchEnd;}///// <summary>/// 单个手指 移动/// </summary>/// <param name="gesture"></param>void On_SwipeEnd(Gesture gesture){if (start){switch (gesture.swipe){case EasyTouch.SwipeDirection.DownLeft://单手指 向 下左 移动cameraMove(10, 10);break;case EasyTouch.SwipeDirection.UpLeft://单手指 向 上左 移动cameraMove(10, -10);break;case EasyTouch.SwipeDirection.Left://单手指 向 左 移动cameraMove(10, 0);break;case EasyTouch.SwipeDirection.DownRight://单手指 向 下右 移动cameraMove(-10, 10);break;case EasyTouch.SwipeDirection.UpRight://单手指 向 上右 移动cameraMove(-10, -10);break;case EasyTouch.SwipeDirection.Right://单手指 向 右 移动cameraMove(-10, 0);break;case EasyTouch.SwipeDirection.Up://单手指 向 上 移动cameraMove(0, -10);break;case EasyTouch.SwipeDirection.Down://单手指 向 下 移动cameraMove(0, 10);break;}}}/// <summary>/// 开始游戏,注册 事件/// </summary>public void StartGame(){start = true;EasyTouch.On_SwipeEnd += On_SwipeEnd;EasyTouch.On_TouchStart2Fingers += On_TouchStart2Fingers;EasyTouch.On_PinchIn += On_PinchIn;EasyTouch.On_PinchOut += On_PinchOut;EasyTouch.On_PinchEnd += On_PinchEnd;}#region 两个手指控制// At the 2 fingers touch beginningprivate void On_TouchStart2Fingers(Gesture gesture){}/// <summary>/// 两个手指 缩小/// </summary>/// <param name="gesture"></param>// At the pinch inprivate void On_PinchIn(Gesture gesture){}///// <summary>/// 两个手指 放大/// </summary>// At the pinch outprivate void On_PinchOut(Gesture gesture){}// At the pinch endprivate void On_PinchEnd(Gesture gesture){}#endregion//两个手指控制
Assets\EasyTouchBundle\EasyTouch\Plugins\Engine\Gesture.cs
Gesture里面全都是EasyTouch的事件的返回的值
...
public class Gesture : BaseFinger,ICloneable
{
/// <summary>/// The siwpe or drag type ( None, Left, Right, Up, Down, Other => look at EayTouch.SwipeType enumeration).滑动或拖拽 方向类型,无、左、右、上、下、其他/// </summary>public EasyTouch.SwipeDirection swipe; /// <summary>/// The length of the swipe.滑动距离/// </summary>public float swipeLength; /// <summary>/// The swipe vector direction.滑动方向矢量/// </summary>public Vector2 swipeVector; /// <summary>/// The pinch length delta since last change.自上次更改以来的夹点长度增量。 /// </summary>public float deltaPinch; /// <summary>/// The angle of the twist.扭曲的角度 /// </summary>public float twistAngle; /// <summary>/// The distance between two finger for a two finger gesture.两指手势的两指之间的距离。/// </summary>public float twoFingerDistance;public EasyTouch.EvtType type = EasyTouch.EvtType.None;#region public methodpublic object Clone(){return this.MemberwiseClone();}/// <summary>/// Transforms touch position into world space, or the center position between the two touches for a two fingers gesture.将触摸位置转换为世界空间,或两个手指手势的两次触摸之间的中心位置。 /// </summary>/// <returns>/// The touch to wordl point.接触世界点。/// </returns>/// <param name='z'>/// The z position in world units from the camera or in world depending on worldZ value来自相机的世界单位的 z 位置或世界中的 z 位置取决于 worldZ 值 /// </param>/// <param name='worldZ'>/// true = r/// </param>/// public Vector3 GetTouchToWorldPoint(float z){return Camera.main.ScreenToWorldPoint( new Vector3( position.x, position.y,z)); }public Vector3 GetTouchToWorldPoint( Vector3 position3D){return Camera.main.ScreenToWorldPoint( new Vector3( position.x, position.y,Camera.main.transform.InverseTransformPoint(position3D).z)); }/// <summary>/// Gets the swipe or drag angle. (calculate from swipe Vector)获取滑动或拖动角度。 (从滑动向量计算)/// </summary>/// <returns>/// Float : The swipe or drag angle.滑动或拖动角度/// </returns>public float GetSwipeOrDragAngle(){return Mathf.Atan2( swipeVector.normalized.y,swipeVector.normalized.x) * Mathf.Rad2Deg; }/// <summary>/// Normalizeds the position.标准化位置/// </summary>/// <returns>/// The position./// </returns>public Vector2 NormalizedPosition(){return new Vector2(100f/Screen.width*position.x/100f,100f/Screen.height*position.y/100f); }/// <summary>/// Determines whether this instance is over user interface element.确定此实例是否在用户界面元素上。/// </summary>/// <returns><c>true</c> if this instance is over user interface element; otherwise, <c>false</c>.</returns>public bool IsOverUIElement(){return EasyTouch.IsFingerOverUIElement( fingerIndex);}/// <summary>/// Determines whether this instance is over rect transform the specified tr camera.确定此实例是否对指定的 tr 相机进行了 rect 变换。/// </summary>/// <returns><c>true</c> if this instance is over rect transform the specified tr camera; otherwise, <c>false</c>.</returns>/// <param name="tr">Tr.</param>/// <param name="camera">Camera.</param>public bool IsOverRectTransform(RectTransform tr,Camera camera=null){if (camera == null){return RectTransformUtility.RectangleContainsScreenPoint( tr,position,null);}else{return RectTransformUtility.RectangleContainsScreenPoint( tr,position,camera);}}/// <summary>/// Gets the first picked user interface element.获取第一个选择的用户界面元素。/// </summary>/// <returns>The first picked user interface element.</returns>public GameObject GetCurrentFirstPickedUIElement(bool isTwoFinger=false){return EasyTouch.GetCurrentPickedUIElement( fingerIndex,isTwoFinger);}/// <summary>/// Gets the current picked object.获取当前选取的对象。/// </summary>/// <returns>The current picked object.</returns>public GameObject GetCurrentPickedObject(bool isTwoFinger=false){return EasyTouch.GetCurrentPickedObject( fingerIndex,isTwoFinger);}#endregion
}
...
说明:
On_SwipeStart(开始拖拽)
使用On_SwipeEnd事件(拖拽结束)的时候,gesture.swipeLength的值不为0.
使用On_Swipe事件(拖拽中)的时候,gesture.swipeLength始终为0,通过gesture.swipeVector拖拽方向矢量 来计算 距离,这个方向矢量是距离(0,0)的方向矢量,这个(0,0)为拖拽开始的点为起始点。
...Vector2 vec2 = gesture.swipeVector;float value = 0;//gesture.swipeLength;float distance = Vector2.Distance(vec2,Vector2.zero);value = distance;//拖拽中的距离值,不拖拽方向矢量为0
...
On_Swipe拖拽中和 手指捏On_PinchIn和On_PinchOut如果不用 逻辑判断,就会造成 两个事件同时执行。
如果不判断 手指 触摸 屏幕 的数量(参考资料6),也会造成 On_Swipe拖拽中和 手指捏On_PinchIn和On_PinchOut事件的BUG
.../// <summary>/// 是否 手指捏/// </summary>private bool isPinch = false;/// <summary>/// 是否 滑动/// </summary>private bool isSwipe = false;
...void On_SwipeEnd(Gesture gesture)//滑动结束{if (EasyTouch.GetTouchCount() == 1){ isSwipe = false;Debug.Log("手指测试 滑动结束:" + isSwipe);}}//void On_Swipe(Gesture gesture){if (start&& isPinch == false&& EasyTouch.GetTouchCount() == 1){...}}private void On_PinchEnd(Gesture gesture)//手指捏 事件 结束{isPinch = false;Debug.Log("手指测试 缩放结束:" + isPinch+"/:"+ Input.touches.Length);}///// <summary>/// 两个手指 缩小/// </summary>/// <param name="gesture"></param>// At the pinch inprivate void On_PinchIn(Gesture gesture){if (isSwipe == false&& EasyTouch.GetTouchCount() == 2){ ...}//}///// <summary>/// 两个手指 放大/// </summary>// At the pinch outprivate void On_PinchOut(Gesture gesture){if (isSwipe == false&& EasyTouch.GetTouchCount() == 2){ ...}}
...
参考资料:
1.Easy Touch组件API详解
2.Unity3d 插件研究之EasyTouch插件
3.最新easyTouch 5.0.12和中英文文档
4.EasyTouch 5.0.17.以及5.0.12和校验中问文档.rar
5.[Unity]EasyTouch英文文档位置在哪
6.[Unity][EasyTouch]判断触摸屏幕手指数量
7.
[Unity]EasyTouch手指滑动返回距离值相关推荐
- [Unity]EasyTouch手指事件说明
如何使用EasyTouch事件,参考资料4 Unity项目导入EasyTouch插件 Assets\EasyTouchBundle\EasyTouch\Examples\4.X\SimpleExamp ...
- 移动端手指滑动的距离
function wetherScroll(){var startX = startY = endX =endY =0;document.addEventListener('touchstart',f ...
- MotionEvent判断手指滑动的距离
分析:点击屏幕会触发down move up 判断手指是否执行了移动操作 获取x,y的坐标值 MotionEvent.ACTION_DOWN:方法中获取x,y的坐标 case MotionEvent. ...
- unity中手指滑动事件
using UnityEngine; using System.Collections;public class jarodInputController : MonoBehaviour {priva ...
- uniapp 简单有效判断手指滑动方向
@touchstart="touchStart"@touchend="touchEnd"@touchmove='move' 首先 是在uniapp中运用这三个方 ...
- android仿苹果悬浮窗(自动停靠、随手指滑动、返回主屏幕)
说明:本人写博客一来是为了方便日后查看项目,二来是希望能够和广大的程序猿相互交流学习,文章布局简单,如有嫌弃,请绕行,如有错误,请指出,谢谢. 实验环境:安卓6.0 魅族手机 悬浮窗主要有以下几个功能 ...
- Unity协程的返回值
使用协程要引入的命名空间:using System.Collections; unity 之协程返回值 yield return null; // 下一帧再执行后续代码 yield return 6; ...
- 手指滑动控制系统全局音量的程序(中)
这次的目标是做出一个通过摄像头检测手指滑动,从而可以调整系统全局音量的程序 接着上一篇继续讲 功能实现 1.OpenCV的视频处理 0表示使用系统默认的摄像头 使用一个用久成立的循环,使视频中的每一帧 ...
- jquery 手指滑动多半屏_JS拖拽专题(五)——「玩出花儿来」移动端滑动事件的封装...
欢迎来到我的JS拖拽专题系列文章,本章节将是拖拽系列的最后一篇.感谢大家的支持^_^ 上一章节我们说到了拖拽让图片相互之间交换位置,相对来说是一个比较综合的示例,涉及到了矩形的碰撞检测,勾股定理计算两 ...
最新文章
- 互联网架构师必备技术 Docker仓库与Java应用服务动态发布那些事
- Guava Cache探索及spring项目整合GuavaCache实例
- SAP WebClient UI开发工具中attribute文件夹展开的实现原理分析
- 一文搞定面试中的二叉树问题
- 华扬联众携手搜狗,助雅诗兰黛跃居女神节“C位”
- SAP License:ERP系统管理软件该有的“魅力”
- 只腐蚀毛刺 腐蚀算法_工件刺虽小,去除却难!介绍几种先进去毛刺工艺,操作简单实用...
- Mac安装 MySQL 及可视化工具
- 网页设计配色应用实例剖析—蓝色系
- 模型结构可视化神器——Netron(支持tf, caffe, keras,mxnet等多种框架)
- “用户体验及可用性测试”前三章:读书笔记
- Vue.js如何获得兄弟元素,子元素,父元素(DOM操作)
- Git - 版本穿梭(时光穿梭机)
- python定义函数求解一元二次方程
- 74LS148 编码器 【数字电路】
- Swift —— 类与结构体
- Ubuntu20.04 安装python3.7
- OSChina 周四乱弹 ——如何把合租女骗上床
- 【模拟面试-10年工作】项目多一定是优势吗?
- 微软使用郑码输入法10年未付费遭起诉