在 MRTK 2 中访问 VR 控制器游戏对象引用?

Accessing VR Controller GameObject references in MRTK 2?

我目前正在开发一个应用程序,我需要将一些对象粘贴到用户的运动控制器上,但我似乎找不到获取引用的方法。

来自在 运行 时间之外暴露游戏对象的 VRTK,事实证明这对我来说是一个挑战。在 MRTK 上有更好的方法吗?

要获取控制器的 "proxy" 游戏对象,您可以使用下面的代码(请参阅它的第一部分,它使用可视化工具的代理游戏对象)。

也可以获取指针的游戏对象(注意给定的控制器可能有很多指针)

如果其中的某些术语令人困惑,我还建议您阅读以下内容: https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/Architecture/InputSystem/Terminology.html

其中解释了一些正在使用的术语以及它们之间的关系。

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

public class ControllerPointers : MonoBehaviour
{
   private IMixedRealityInputSystem inputSystem = null;

   /// <summary>
   /// The active instance of the input system.
   /// </summary>
   protected IMixedRealityInputSystem InputSystem
   {
       get
       {
           if (inputSystem == null)
           {
               MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
           }
           return inputSystem;
       }
   }

   // Update is called once per frame
   void Update()
   {
       // Log something every 60 frames.
       if (Time.frameCount % 60 == 0)
       {
           foreach (IMixedRealityController controller in InputSystem.DetectedControllers)
           {
               if (controller.Visualizer?.GameObjectProxy != null)
               {
                   Debug.Log("Visualizer Game Object: " + controller.Visualizer.GameObjectProxy);
               }
               else
               {
                   Debug.Log("Controller has no visualizer!");
               }


               foreach (IMixedRealityPointer pointer in controller.InputSource.Pointers)
               {
                   if (pointer is MonoBehaviour)
                   {
                       var monoBehavior = pointer as MonoBehaviour;
                       Debug.Log("Found pointer game object: " + (monoBehavior.gameObject));
                   }
               }
           }
       }
   }
}

最后,您也可以始终从指针接口本身获取 position/rotation/velocity 属性(即在上面的代码中,使用指针位置:https://microsoft.github.io/MixedRealityToolkit-Unity/api/Microsoft.MixedReality.Toolkit.Input.IMixedRealityPointer.html#Microsoft_MixedReality_Toolkit_Input_IMixedRealityPointer_Position

检查 MRTK 解算器。 https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/README_Solver.html

本教程在第 4 步中介绍了如何将立方体 "stick" 连接到控制器。 (听起来像你的问题) https://docs.microsoft.com/en-us/windows/mixed-reality/mrlearning-base-ch3

Once you select the hand joint, you can choose which part of the hand you want >the cube to follow. For this example, we are going to use the wrist. Next to >the option Tracked Hand Joint select the dropdown menu and select Wrist.

有两件事要提...我的自定义 "controllers" 有问题(我已经用 Oculus 手覆盖了默认控制器)还要检查您是否需要 "hand joints"(就像在教程)或者如果您想使用下拉列表中的 "motion controller left" 条目。