(五)Hololens Unity 开发之 手势识别
**学习源于官方文档 Gestures in Unity **
笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文
(五)Hololens Unity 开发之 手势识别
HoloLens 有三大输入系统,凝视点、手势和声音 ~ 本文主要记录手势识别的学习笔记 ~
一、概述
Gestures are the second "G" in Gaze, Gesture, and Voice. Unity provides both low level access (raw position and velocity information) and a high level gesture recognizer that exposes more complex gesture events (for example: tap, double tap, hold, manipulation and navigation).
手势识别是Hololens 三大输入系统 Gaze焦点、Gesture手势 和 Voice声音 中的第二个G(这句翻译的好像有点儿生硬了)同时在Unity层面也提供了底层的API,例如原始位置速度位移信息等~ 当然,也提供了高维度封装好的供开发者调用的高层API例如:手势单击,双击,长按,多点点击以及导航栏...(完全按照开发者的思维翻译的)
官文可以得知~ HoloLens提供了高层次的和核心的API供开发者调用~
2
- Gesture Input
- Interaction Input
二、Gesture Input(高层次分装的API)
Namespace: UnityEngine.VR.WSA.Input
Types: GestureRecognizer, GestureSettings, InteractionSourceKind
These high level gestures are generated by input sources. Each Gesture event provides the SourceKind for the input as well as the targeting head ray at the time of the event. Some events provide additional context specific information.
这是一些高层次的手势源,每个手势输入都对应了一个事件event~ 而每个事件都提供了SourceKind 手势输入员的类别 以及 在 头部感应器触发事件的事件~ 而且一些事件来提供了额外的一些信息~
高层的封装代表着简洁,方便,快捷所以我们只要通过下面几个步骤我们就能实现手势识别了
创建一个手势识别对象 Gesture Recognizer
设置手势监听的类型
注册事件
开启手势识别的功能
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VR.WSA.Input;public class GestureDemo : MonoBehaviour {
private GestureRecognizer recognizer; // Use this for initialization
void Start () {
Debug.Log("初始化开始~");
// 创建手势识别对象
recognizer = new GestureRecognizer();
// 设置手势识别的类型
recognizer.SetRecognizableGestures(GestureSettings.Tap | GestureSettings.Hold | GestureSettings.DoubleTap);
// 添加手势识别的事件
recognizer.TappedEvent += Recognizer_TappedEvent;
recognizer.HoldStartedEvent += Recognizer_HoldStartedEvent;
recognizer.HoldCompletedEvent += Recognizer_HoldCompletedEvent;
recognizer.HoldCanceledEvent += Recognizer_HoldCanceledEvent;
// 开启手势识别
recognizer.StartCapturingGestures();
Debug.Log("初始化完成~");
} private void Recognizer_HoldCanceledEvent(InteractionSourceKind source, Ray headRay)
{
Debug.Log("Recognizer_HoldCanceledEvent 枚举类型应该为1 ~ " + source);
} private void Recognizer_HoldCompletedEvent(InteractionSourceKind source, Ray headRay)
{
Debug.Log("Recognizer_HoldCompletedEvent 枚举类型应该为1 ~ " + source);
} private void Recognizer_HoldStartedEvent(InteractionSourceKind source, Ray headRay)
{
Debug.Log("Recognizer_HoldStartedEvent 枚举类型应该为1 ~ " + source);
} private void Recognizer_TappedEvent(InteractionSourceKind source, int tapCount, Ray headRay)
{
Debug.Log("Recognizer_TappedEvent 枚举类型应该为1 ~ " + source + " 点击的次数 " + tapCount);
} void OnDestroy()
{
// 销毁注册的事件
recognizer.TappedEvent -= Recognizer_TappedEvent;
recognizer.HoldStartedEvent -= Recognizer_HoldStartedEvent;
recognizer.HoldCompletedEvent -= Recognizer_HoldCompletedEvent;
recognizer.HoldCanceledEvent -= Recognizer_HoldCanceledEvent;
}
}
一切尽在代码中~
三、Interaction Input(核心API)
Namespace: UnityEngine.VR.WSA.Input
Types: InteractionManager, InteractionSourceState, InteractionSource, InteractionSourceProperties, InteractionSourceKind, InteractionSourceLocation
1、API介绍
手势交互核心层的API调用分厂简单,三步搞定~
注册手势交互的事件
接收事件回调
移除手势交互的事件
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VR.WSA.Input;public class InteractionDemo : MonoBehaviour {
// Use this for initialization
void Start () {
// 点击某个控件的事件
InteractionManager.SourcePressed += InteractionManager_SourcePressed;
// 点击某个控件放开的事件
InteractionManager.SourceReleased += InteractionManager_SourceReleased;
// 选中某个控件的事件
InteractionManager.SourceDetected += InteractionManager_SourceDetected;
// 选中后再不选中的事件
InteractionManager.SourceLost += InteractionManager_SourceLost;
// 更新某个控件的事件
InteractionManager.SourceUpdated += InteractionManager_SourceUpdated;
} private void InteractionManager_SourceUpdated(InteractionSourceState state)
{
throw new System.NotImplementedException();
} private void InteractionManager_SourceReleased(InteractionSourceState state)
{
throw new System.NotImplementedException();
} private void InteractionManager_SourceLost(InteractionSourceState state)
{
throw new System.NotImplementedException();
} private void InteractionManager_SourceDetected(InteractionSourceState state)
{
throw new System.NotImplementedException();
} private void InteractionManager_SourcePressed(InteractionSourceState state)
{
throw new System.NotImplementedException();
} void OnDestroy()
{
// 移除各种手势的事件
InteractionManager.SourceDetected -= InteractionManager_SourceDetected;
InteractionManager.SourceUpdated -= InteractionManager_SourceUpdated;
InteractionManager.SourceLost -= InteractionManager_SourceLost;
InteractionManager.SourcePressed -= InteractionManager_SourcePressed;
InteractionManager.SourceReleased -= InteractionManager_SourceReleased;
}
}
2、InteractionSourceState 结构体
源码~
namespace UnityEngine.VR.WSA.Input
{
[RequiredByNativeCodeAttribute]
public struct InteractionSourceState
{
public Ray headRay { get; }
public bool pressed { get; }
public InteractionSourceProperties properties { get; }
public InteractionSource source { get; }
}
}
- headRay 这个变量可以确定该事件发生时用户头部所处的位置信息
- pressed 是否处于点击状态
- InteractionSourceProperties 可以通过InteractionSourceProperties获得输入源的位置、速度以及输入源的时间点
- InteractionSource 枚举类型,可以是不同的输入类型,包括手势 声音 控制器 以及 其他等等~
(五)Hololens Unity 开发之 手势识别的更多相关文章
- (二)Hololens Unity 开发之 语音识别
学习源于官方文档 Voice input in Unity 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 (二)Hololens Unity 开发之 语音识别 Hol ...
- (二)Hololens Unity 开发入门 之 Hello HoloLens~
学习源于官方文档 微软官文~ 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 (二)Hololens Unity 开发入门 之 Hello HoloLens~ 本文主要 ...
- (三)Hololens Unity 开发之 语音识别
学习源于官方文档 Voice input in Unity 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 (三)Hololens Unity 开发之 语音识别 Hol ...
- (一)Hololens Unity 开发环境搭建(Mac BOOTCAMP WIN10)
(一)Hololens Unity 开发环境搭建(Mac BOOTCAMP WIN10) 系统要求 64位 Windows 10 除了家庭版的 都支持 ~ 64位CPU CPU至少是四核心以上~ 至少 ...
- (四)Hololens Unity 开发之 凝视系统
学习源于官方文档 Gaze in Unity 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 HoloLens 有三大输入系统,凝视点.手势和声音 ~ 本文主要记录凝视 ...
- HoloLens开发手记 - Unity development overview 使用Unity开发概述
Unity Technical Preview for HoloLens最新发行版为:Beta 24,发布于 09/07/2016 开始使用Unity开发HoloLens应用之前,确保你已经安装好了必 ...
- 使用Unity开发HoloLens应用
https://developer.microsoft.com/en-us/windows/holographic/install_the_tools 导读:开发者们在陆续收到HoloLens开发者版 ...
- Unity开发概览(HoloLens开发系列)
本文翻译自:Unity development overview 要开始使用Unity创建全息应用,点此安装包含Unity HoloLens技术预览的开发工具.Unity HoloLens技术预览基于 ...
- 【Holograms 101D】一步步用Unity 开发 Hologram
转载请注明出处: copperface:[Holograms 101D]一步步用Unity 开发 Hologram Holograms 101 该教程将带领你走完 Hologram 创建 的全过程.整 ...
随机推荐
- Xcode 6配置里定义${ARCHS_STANDARD}为armv7, arm64以及错误
转发:http://www.cocoachina.com/ios/20141013/9897.html 最近一次的Xcode 6更新默认不再支持arm7s架构,究竟是要废除不用呢还是仅仅只是一个疏忽? ...
- Blog`s CSS
#div_digg { position: fixed; bottom: 10px; width: 50px; right: 50px; filter: alpha(opacity=20); opac ...
- 11.10document对象练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- CentOS 6.4 x64 zabbix 2.2.2 编译安装
A. 服务端安装配置 1.下载zabbix 2.x 最新版本 http://www.zabbix.com/download.php 2.安装配置所需要软件(zabbix需要一个lamp环境) 使用 y ...
- Linux系统目录
[root@localhost ~]# ls /bin dev home lost+found misc opt root selinux sys usrboot etc lib media net ...
- COM问题
因为应用程序正在发送一个输入同步呼叫,所以无法执行传出的呼叫.
- phpMyAdmin安装与配置(涉及LAMP配置)
作者:zccst 安装一个phpMyAdmin还真麻烦,遇到很多问题.不过在解决过程中发现,PHP的水还真深,不是短时间可以看透的. 1,下载 建议去百度软件中心下载 2,使用 (1)解压后,复制配置 ...
- USB自定义HID设备实现-LPC1768
首先在之前鼠标的基础上修改设备描述符 #include "usbdesc.h" //usb标准设备描述符 const U8 USB_DeviceDescriptor[] = { U ...
- 试水mongodb er
1)data ready var a = {"name":"zhekou","CharDate":"2015-12-01" ...
- Java 汉子转拼音
1. 引入: pinyin4j-1.1.0 包; http://pan.baidu.com/s/1eQ8a874 2. 转换; private static String ChineseToPiny ...