如何在不必用 cursor/pointer 指向某物的情况下检测到空中窃听?

How to detect an air-tap without having to point something with the cursor/pointer?

我正在使用 Unity 和 MRTK 制作 HoloLens 2 应用程序,当用户执行隔空敲击手势时,我需要在用户手的坐标中实例化一个游戏对象,我试图使用 IMixedRealityInputHandler,但问题是为了检测隔空敲击手势,用户需要指向具有实现该接口的脚本的游戏对象,

知道如何在不需要直接指向某物的情况下检测到空气窃听器吗?

要监听输入事件并忽略焦点是什么GameObject,您可以创建一个组件注册全局输入处理程序,更多信息请参见:Register for global input events

为了提供更具体的答案,我在下面提供了测试代码。这是基于 Eduardo 的回答。

...you can create a component registered global input handlers, more information please see:Register for global input events

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

public class AirTapper : MonoBehaviour, IMixedRealityGestureHandler
{
    private void OnEnable()
    {
        // Instruct Input System that we would like to receive all input events of type IMixedRealityGestureHandler
        CoreServices.InputSystem?.RegisterHandler<IMixedRealityGestureHandler>(this);
    }

    private void OnDisable()
    {
        // Instruct Input System to disregard all input events of type IMixedRealityGestureHandler
        CoreServices.InputSystem?.UnregisterHandler<IMixedRealityGestureHandler>(this);
    }
    
    public void OnGestureStarted(InputEventData eventData)
    {
        Debug.Log("Gesture started: " + eventData.MixedRealityInputAction.Description);
    }
    
    public void OnGestureUpdated(InputEventData eventData)
    {
    }
    
    public void OnGestureCompleted(InputEventData eventData)
    {
        Debug.Log("Gesture completed: " + eventData.MixedRealityInputAction.Description);
    }
    
    public void OnGestureCanceled(InputEventData eventData)
    {
    }
}