手势识别是HoloLens交互的重要输入方式之一。HoloLens提供了底层访问和高水平手势识别,可以满足不同的手势定制需求。底层访问能够获取手的原始位置和速度信息,高层识别则借助手势识别器来识别预设手势(包括,单击、双击、长按、操纵、导航、平移等等)。
手势输入
命名空间:UnityEngine.VR.WSA.Input
类型:GestureRecognizer,GestureSettings,InteractionSourceKind
高级识别是通过输入源来识别手势。每个手势对应一个SourceKind输入源,大部分手势事件都是系统预设的事件,有些事件会提供额外的上下文信息。
只需要几步就能使用GestureRecognizer集成手势识别:
1. 创建GestureRecognizer实例
2. 注册指定的手势类型
3. 订阅手势事件
4. 开始手势识别
创建新的手势识别
你必须创建一个GestureRecognizer才可以使用。

指定手势
在via SetRecognizableGestures()指定手势

订阅手势

注意:Navigation(导航)和Manipulation(操控)手势在GestureRecognizer是互斥的。
开始捕捉手势

停止捕捉手势

停止手势识别

交互输入
命名空间:UnityEngine.VR.WSA.Input
类型:InteractionManager,InteractionSourceState,InteractionSource,InteractionSourceProperties,InteractionSourceKind,InteractionSourceLocation
低层次的空间输入可以让你获得更多的输入来源的更多详细信息,比如它在世界中的位置和速度。
如何处理交互事件
使用交互输入很容易:
1.注册InteractionManager事件
2.处理事件
停止它也很容易:
取消注册事件
注册交互事件
对于每种你需要的交互事件类型,你都要进行注册。

处理交互事件
一旦注册了交互事件,在事件发生时你就可以得到回调。你可以使用获取到的时间信息来处理应用行为。

如何停止交互
当你不再想要关注一些事件后,只需要取消时间注册即可。
注销交互事件
注销账户可停止处理事件

输入源变化事件
这些事件描述了输入源的状态:
· detected(即将激活)
· lost(即将取消激活)
· updates(移动或者一些状态正在变化)
· is pressed(点击、按钮按下或者语音选中)
· is released(点击结束,按钮松开,语音选中结束)
输入源状态
每个事件都会有一个InteractionSourceState参数,这个参数代表了实时输入源状态:
· 是否进入点击状态
· InteractionSourceProperties包含了输入源位置信息InteractionSourceLocation,能够获得当前输入源位置和速度信息
· 凝视射线信息,用于判断事件发生时用户是否在注视目标
· 来源类型信息,包括hand、voice、controller或者其他类型
代码实例

10.png(28.64 KB, 下载次数: 13)
2016-6-27 10:43 上传

网友评论