(五)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 创建 的全过程.整 ...
随机推荐
- Java内存回收 - 落日之心的日志 - 网易博客
body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...
- [Asp.Net Core轻量级Aop解决方案]AspectCore Project 介绍
AspectCore Project 介绍 什么是AspectCore Project ? AspectCore Project 是适用于Asp.Net Core 平台的轻量级 Aop(Aspect- ...
- [python]小练习__创建你自己的命令行 地址簿 程序
创建你自己的命令行 地址簿 程序. 在这个程序中,你可以添加.修改.删除和搜索你的联系人(朋友.家人和同事等等)以及它们的信息(诸如电子邮件地址和/或电话号码). 这些详细信息应该被保存下来以便以后提 ...
- Spring自学教程-AOP学习(五)
Spring中的AOP 一.概述 (一)基本概念 1.什么是AOP? 面向方面编程.所谓方面即是指日志.权限.异常处理.事务处理等. 2.AOP的3个关键概念 (1)切入点(Pointc ...
- HTML5 - Canvas动画样例(谷歌弹跳球)
1,样例说明 (1)在没有鼠标介入的情况下,这些球就像有磁性一样拼成"Google"字样. (2)在鼠标移动到其中后,小球像是受到了排斥,向画布的四周扩散,然后不规则地反弹回来. ...
- FZU 2112 Tickets
这个问题可以转变一下,先要知道有几个连通块,连通块之间肯定需要添加一条边, 还需要知道每个连通块内部需要添加几条边,这个问题等价于求一张图至少需要几笔画成,这个问题的答案是度为奇数的点的个数/2 #i ...
- 2016年最全面的VR资源盘点,不只有VR视频播放器还有具体到步骤的VR资源
2016年过去了,有多少人开始使用VR来观看我们喜欢的视频资源呢?比传统视频更高的沉浸感,甚至在VR眼镜的视角中,自己仿佛化生成视频中的主角一般.然而,这种体验只有VR眼镜还是不行的,还需要有一个VR ...
- C# GridView Edit & Delete, 点击Delete的时候弹出确认框
1. 使用GridView自带属性ShowEditButton和ShowDeleteButton,均设为True <Columns> ... <asp:CommandField S ...
- Java6 WebService学习
首先,建立一个WebService: package garfield; import javax.jws.WebService; import javax.xml.ws.Endpoint; @Web ...
- 关于学习方法的借鉴和有关C语言学习的调查
专长的高超技能获取的成功经验 在游戏方面,我相对于大多数人来说可能更为出色.首先是我投入了大量的时间进行游戏:其次,我几乎每天都会看一会教学视频来模仿:最后应该还是跟个人的天赋有点关系. 如果把这个类 ...