为什么在Unity/MRTK应用程序中的HoloLens1上无法使用“空中敲击"手势? [英] Why is 'air tap' gesture not working on HoloLens1 in my Unity/MRTK app?

查看:73
本文介绍了为什么在Unity/MRTK应用程序中的HoloLens1上无法使用“空中敲击"手势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Unity应用程序,希望与Microsoft Mixed Reality Toolkit(MRTK)集成.当我将MRTK(v2.1或v2.2)程序包添加到Unity项目中时,我可以在Unity Editor中模拟空中敲打"手势,并且该应用会记录该点击.但是,当我将应用程序发布到我的HoloLens1(或在Unity中运行全息仿真器)时,空中点击"手势不会注册点击.

I have a Unity app that I'd like to integrate with the Microsoft Mixed Reality Toolkit (MRTK). When I add the MRTK (v2.1 or v2.2) package to my Unity project, I can simulate the "air tap" gesture in the Unity Editor and the app registers the click. However, when I publish the app to my HoloLens1 (or run the holographic emulator within Unity), the "air tap" gesture does not register a click.

团结:2018.4.x

Unity: 2018.4.x

MRTK :均为v2.1/v2.2

MRTK: both v2.1 / v2.2

统一场景设置:

  • 具有一个带有独立输入模块的EventSystem
  • 具有一个作为主摄像机的角色
  • 已导入MRTK
  • 混合现实工具包配置文件设置为 DefaultHoloLens1ConfigurationProfile

当我使用上述设置运行场景时,空中点击会在Unity编辑器中注册(通过按空格键+单击以进行模拟),但是不会在HoloLens1中注册.

When I run the scene with the above setup, the air tap registers in the Unity Editor (by pressing space bar + click to simulate), but it does not register in the HoloLens1.

我缺少部分设置吗?也许要添加到我场景中某物上的另一个输入组件?

Is there some part of the setup I am missing? Perhaps another input component to be added to something in my scene?

推荐答案

要响应来自MRTK的点击事件,您需要收听

To respond to click events from MRTK, you need listen for MRTK pointer events instead of the Unity input events that the MRE is likely listening to. A good event to listen for would be the OnPointerClicked event, which will trigger when a hand is tapped, or when a motion controller is clicked, or if you say the word "select". Normally the input handler will only respond if you are hovering over the object, so to respond to these inputs globally you need to register as a global input handler.

下面是一个脚本示例,该脚本将在每次单击指针时打印一些文本:

Here is an example of a script that will print some text whenever the pointer is clicked:

using Microsoft.MixedReality.Toolkit;
using Microsoft.MixedReality.Toolkit.Input;
using UnityEngine;

public class DetectTapExample : MonoBehaviour
{

    public void Start()
    {
        PointerHandler pointerHandler = gameObject.AddComponent<PointerHandler>();
        pointerHandler.OnPointerClicked.AddListener((evt) => Debug.Log("Tap Detected " + Time.time));
        // Make this a global input handler, otherwise this object will only receive events when it has input focus
        CoreServices.InputSystem.RegisterHandler<IMixedRealityPointerHandler>(pointerHandler);
    }
}

您可以了解有关此处的MRTK输入系统

这篇关于为什么在Unity/MRTK应用程序中的HoloLens1上无法使用“空中敲击"手势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆