**学习源于官方文档 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 手势输入员的类别 以及 在 头部感应器触发事件的事件~ 而且一些事件来提供了额外的一些信息~

高层的封装代表着简洁,方便,快捷所以我们只要通过下面几个步骤我们就能实现手势识别了

  1. 创建一个手势识别对象 Gesture Recognizer

  2. 设置手势监听的类型

  3. 注册事件

  4. 开启手势识别的功能

    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调用分厂简单,三步搞定~

  1. 注册手势交互的事件

  2. 接收事件回调

  3. 移除手势交互的事件

    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 开发之 手势识别的更多相关文章

  1. (二)Hololens Unity 开发之 语音识别

    学习源于官方文档 Voice input in Unity 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 (二)Hololens Unity 开发之 语音识别 Hol ...

  2. (二)Hololens Unity 开发入门 之 Hello HoloLens~

    学习源于官方文档 微软官文~ 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 (二)Hololens Unity 开发入门 之 Hello HoloLens~ 本文主要 ...

  3. (三)Hololens Unity 开发之 语音识别

    学习源于官方文档 Voice input in Unity 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 (三)Hololens Unity 开发之 语音识别 Hol ...

  4. (一)Hololens Unity 开发环境搭建(Mac BOOTCAMP WIN10)

    (一)Hololens Unity 开发环境搭建(Mac BOOTCAMP WIN10) 系统要求 64位 Windows 10 除了家庭版的 都支持 ~ 64位CPU CPU至少是四核心以上~ 至少 ...

  5. (四)Hololens Unity 开发之 凝视系统

    学习源于官方文档 Gaze in Unity 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 HoloLens 有三大输入系统,凝视点.手势和声音 ~ 本文主要记录凝视 ...

  6. HoloLens开发手记 - Unity development overview 使用Unity开发概述

    Unity Technical Preview for HoloLens最新发行版为:Beta 24,发布于 09/07/2016 开始使用Unity开发HoloLens应用之前,确保你已经安装好了必 ...

  7. 使用Unity开发HoloLens应用

    https://developer.microsoft.com/en-us/windows/holographic/install_the_tools 导读:开发者们在陆续收到HoloLens开发者版 ...

  8. Unity开发概览(HoloLens开发系列)

    本文翻译自:Unity development overview 要开始使用Unity创建全息应用,点此安装包含Unity HoloLens技术预览的开发工具.Unity HoloLens技术预览基于 ...

  9. 【Holograms 101D】一步步用Unity 开发 Hologram

    转载请注明出处: copperface:[Holograms 101D]一步步用Unity 开发 Hologram Holograms 101 该教程将带领你走完 Hologram 创建 的全过程.整 ...

随机推荐

  1. SQL复习六(视图)

    视图是关系数据库系统提供给用户以多角度观察数据库中数据的一种重要方法.视图是从一个或者几个表中导出的虚拟表.视图一经定义就可以被查询和删除.也可以在视图上定义视图.用视图完成数据的更新(增,删,改)操 ...

  2. php 中的全局变量的理解

    $GLOBALS 是php中的一个全局变量的数组. $GLOBALS['var1']  代表的是 外部的全局变量 $var1 本身.global $var是外部$var的同名引用或者指针 例1: &l ...

  3. jquery如何判断元素是否被点击_百度知道

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <div id="parent"> <a id="a1" ...

  4. iOS navigationBar 的isTranslucent属性

    苹果文档: A Boolean value indicating whether the navigation bar is translucent (YES) or not (NO). The de ...

  5. Codeforces#360Div2

    A题 题意:给定d个操作,每个操作当中只包含1和0,若存在0,则表示操作者获胜,求最大的连续获胜个数 分析:直接统计之后用一个数组纪录下来即可 #include <iostream> #i ...

  6. ubuntu16安装KVM

    apt install qemu-kvm libvirt-bin apt install openvswitch-switch

  7. 编译Uboot时提示error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory

    在Ubuntu14.04 64位系统中已经安装了libc6:i386的库,编译Uboot时提示error while loading shared libraries: libz.so.1: cann ...

  8. CSS实现导航条Tab切换的三种方法

    前面的话   导航条Tab在页面中非常常见,本文说详细介绍CSS实现导航条Tab的三种方法 布局   根据上图所示,先规定几个定义,上图的模块整体叫做导航,由导航标题和导航内容组成.要实现上图所示的布 ...

  9. make 要点简记

    make 要点简记 1.隐式推导 make可以自动推导文件及其文件依赖关系后面的命令,所以我们没有必要在每一个.o文件后面都写上类似的命令,因为make 会自动识别并且自动推导命令. objects ...

  10. UVa 11450 - Wedding shopping

    题目大意:我们的朋友Bob要结婚了,所以要为他买一些衣服.有m的资金预算,要买c种类型的衣服(衬衫.裤子等),而每种类型的衣服有k个选择(只能做出一个选择),每个选择的衣服都有一个价格,问如何选择才能 ...