【Unity插件】FingerGestures导入使用教程
来源:互联网 发布:seo搜索引擎优化能赚钱 编辑:程序博客网 时间:2024/05/20 16:14
转载地址:http://blog.csdn.net/highning0007/article/details/37991649
FingerGestures
FingerGestures是一款强大的手势识别插件,支持鼠标和触控。跨平台,最新的3.0版本支持自定义手势识别。
其中CustomGestures的识别还是挺准的。测试画个一笔五角星,能被容易的识别。
其中CustomGestures的识别还是挺准的。测试画个一笔五角星,能被容易的识别。
一.安装
直接解压包,里面还有samples和对playerMaker拓展 2个子包。
二.导入Sample包
在搜索栏里输入 t:scene, 然后全选场景并拖入Build Setting里的Scenes in Build
把'Sample Browser'场景调整到第一个场景
也可在player setting里把屏幕设置为600x400
三.基本识别 GestureRecognizers(检测用户输入并发送事件)
识别单击
场景里必须只有一个FingerGestures组件示例。它相当于Manager。
(1)直接新建GameObject起名Manager,并加FingerGestures脚本
(2)直接新建GameObject起名Gestures,并加TapRecognizer脚本
(3)直接新建TapTutorial.cs 并放到Gestures上
(4)在Gestures里TapRecognizer面板下,点"Copy Event To Clipboard" 把对应代码拷贝到粘贴板上,并在TapTutorial脚本里粘贴代码。
当recognizer检测对应输入到后, 会在obj上发对应的SendMessage消息。但是SendMessage开销大,可以自己实现开销更小的delegate-based events.
5)打输出debug信息的代码最终脚本using UnityEngine;using System.Collections;public class TapTutorial : MonoBehaviour {void OnTap(TapGesture gesture){ Debug.Log( "Tap gesture detected at " + gesture.Position + ". It was sent by " + gesture.Recognizer.name );}}
识别单击物体
(1)创建球,确保有collider或者trigger,位置(0,1,0),缩放(4,4,4)
(2)Gesture物体上加 ScreenRaycaster 脚本
当Ray Thickness为0时 可以是 collider或者trigger,
当Ray Thickness不为0时 必须是 collider, 可以模拟厚手指的操作。
2) 脚本变为using UnityEngine;using System.Collections;public class TapTutorial : MonoBehaviour {void OnTap( TapGesture gesture ) { if( gesture.Selection ) Debug.Log( "Tapped object: " + gesture.Selection.name ); else Debug.Log( "No object was tapped at " + gesture.Position );}}
之后就能检测到点击物体了,并且被点击的圆球同样的收到同名事件
识别2手指Tap3下
设置 Required Finger Count为2
设置 Required Taps为3
如果是电脑运行,用鼠标左右键同时按模拟
四.FingerEventDetector
检测单手指的按下 松开 经过 移动 静止,与GesturesRecognizers类似,发消息,用ScreenRaycaster与物体互动。
FingerEventDetector是抽象类,各种 finger event detectors继承自它。
也可以提供finger index跟踪某指定手指。
(1)新场景,加FingerGestures管理
(2)新物体起名FingerEvent,并加FingerDownDetector
(3)新建脚本FingerEventTutor.cs, 并从FingerDownDetector拷贝粘贴脚本
using UnityEngine;using System.Collections;public class FingerEventTutor : MonoBehaviour {void OnFingerDown(FingerDownEvent e) {Debug.Log( e.Finger + " Down at " + e.Position + " on object:" + e.Selection );}}
点击运行,即可检测任何手指按下的事件。
每个手指事件都要添加对应的detector
using UnityEngine;using System.Collections;public class FingerEventTutor : MonoBehaviour {void OnFingerDown(FingerDownEvent e) {Debug.Log( e.Finger + " Down at " + e.Position + " on object:" + e.Selection );}void OnFingerUp( FingerUpEvent e ) { // time the finger has been held down before being released float elapsedTime = e.TimeHeldDown;Debug.Log( e.Finger + " Up at " + e.Position + " on object:" + e.Selection );}}
五.自定义手势识别
3.0后可以用PointCloudRecognizer来识别自定义手势。算法使用的是$P recognizer. 现在只支持single-stroke(单手指单次画),将会支持multi-strokes.
PointCloudRecognizer将会对比一些gesture模板并返回最接近的 匹配图形,并返回分数和距离值。
PointCloud gestures手势,和缩放以及画的方向无关。但是图形的旋转必须是固定的,例如一个正着摆放的三角形你必须画正的,你画一个倒着摆放的三角形它是不能被识别的。
绘制PointCloud
(1)在Assets栏下,创建 PointCloud Gesture Template,起名MyPCGesture
(2)点击Edit,绘制图形,然后Apply
使用PointCloud
(1)新场景,加FingerGestures管理
(2)创建新的物体起名Gestures
(3) 给 Gestures加 PointCloudRecognizer 组件。
属性
Max Match Distance 用户画的图形distance必须在该值之下, 设定得越小,画得就必须越精确。
Sampling Distance 两个连续手指位置的最小间距。越小表示越精确,但更多的采样
Gesture Template List 要去匹配的图形库
(4) 将MyPCGesture加至 Gesture Template List
(5) 创建PointCloudTutorial.cs脚本并添加至Gestures物体下
using UnityEngine;using System.Collections;public class PointCloudTutorial : MonoBehaviour{ void OnCustomGesture( PointCloudGesture gesture ) { Debug.Log( "Recognized custom gesture: " + gesture.RecognizedTemplate.name + ", match score: " + gesture.MatchScore + ", match distance: " + gesture.MatchDistance ); }}
ointCloudGesture. RecognizedTemplate 对应画出的图形模板
PointCloudGesture. MatchScore 匹配百分比,1代表完美匹配
PointCloudGesture. MatchDistance 与图形有多接近
当然也可以从代码绘制PointCloudGestureTemplate
void Awake(){ PointCloudGestureTemplate triangle =ScriptableObject.CreateInstance<PointCloudGestureTemplate>(); triangle.name = "Triangle Gesture Template"; triangle.BeginPoints(); triangle.AddPoint( 0, 1, 1 ); triangle.AddPoint( 0, 2, 2 ); triangle.AddPoint( 0, 3, 1 ); triangle.AddPoint( 0, 1, 1 ); triangle.EndPoints(); PointCloudGestureTemplate square =ScriptableObject.CreateInstance<PointCloudGestureTemplate>(); square.name = "Square Gesture Template"; square.BeginPoints(); square.AddPoint( 0, 2, 1 ); square.AddPoint( 0, 2, 3 ); square.AddPoint( 0, 4, 3 ); square.AddPoint( 0, 4, 1 ); square.AddPoint( 0, 2, 1 ); square.EndPoints(); PointCloudRegognizer recognizer = gameObject.AddComponent<PointCloudRegognizer>(); recognizer.AddTemplate( triangle ); recognizer.AddTemplate( square );}
AddPoint的第一个参数代表第几画,但是现在只支持一笔画出来的图形,所以该值只填0。当EndPoints()被调用的时候,所有点都会被单位化至(0,1)的范围。
0 0
- 【Unity插件】FingerGestures导入使用教程
- Unity FingerGestures 手势插件教程
- 【Unity插件】FingerGestures 插件使用
- unity手势插件《FingerGestures 》使用入门
- unity中使用FingerGestures插件3.0
- unity手势插件《FingerGestures 》使用入门
- Unity手势插件FingerGestures
- Unity手势插件FingerGestures使用遇到的问题
- Unity手势操作FingerGestures插件
- unityios开发--FingerGestures插件使用
- Unity3D FingerGestures 手势插件使用
- FingerGestures手势插件的使用
- Unity中使用NGUI和FingerGestures插件点击UI穿透的问题
- Unity中使用NGUI和FingerGestures插件点击UI穿透的问题
- 【NGUI】Unity中使用NGUI和FingerGestures插件点击UI穿透的问题
- unity3D的FingerGestures插件
- unity3D的FingerGestures插件
- unity3D的FingerGestures插件
- ida 远程调试
- Log4j源码浅析
- Java EE即将死去,毫无疑问!- Docker & 微服务 & DevOps
- 浅识JQuery基础(一)
- linux添加新硬盘-添加到开机自动挂载
- 【Unity插件】FingerGestures导入使用教程
- 将博客搬至CSDN
- mysql视图操作限制
- caffe学习入门:pycaffe的使用
- 在自定义控件的过程中犯下的错,在调用有三个参数的构造方法时this(context,null,0);第二个参数为空,在Activity中 findViewById找到对应的控件时
- iOS 客户端基于 WebP 图片格式的流量优化(下)
- 【HDU5794】 A Simple Chess(Lucas+容斥)
- Swift基础之使用Alamofire库进行网络请求和断点下载
- 跨机房微服务高可用方案:DerbySoft路由服务设计与实现