Show / Hide Table of Contents

    访问MRTK中的输入状态

    通过遍历连接到输入源的控制器(controller),可以直接查询MRTK中所有输入的状态。MRTK还提供了便捷的方法来访问眼睛,手,头和运动控制器(motion controller)的位置和旋转

    有关通过迭代控制器和使用InputRayUtils 类来查询输入的示例,请参见InputDataExample场景。

    示例:在MRTK中访问头部,手部和眼睛的位置和旋转

    MRTK 的 InputRayUtils 类提供了用于访问手部射线,头部射线,眼睛凝视视线和运动控制器射线的便捷方法。

    // 获取头部射线
    var headRay = InputRayUtils.GetHeadGazeRay();
    
    // 获取右手射线
    Ray rightHandRay;
    if(InputRayUtils.TryGetHandRay(Handedness.right, rightHandRay))
    {
        // 右手射线可用
    }
    else
    {
        // 右手射线不可用
    }
    

    Example: Access position, rotation of all 6DOF controllers active in scene

    foreach(var controller in CoreServices.InputSystem.DetectedControllers)
    {
        // Interactions for a controller is the list of inputs that this controller exposes
        foreach(MixedRealityInteractionMapping inputMapping in controller.Interactions)
        {
            // 6DOF controllers support the "SpatialPointer" type (pointing direction)
            // or "GripPointer" type (direction of the 6DOF controller)
            if (inputMapping.InputType == DeviceInputType.SpatialPointer)
            {
                Debug.Log("spatial pointer PositionData: " + inputMapping.PositionData);
                Debug.Log("spatial pointer RotationData: " + inputMapping.RotationData);
            }
    
            if (inputMapping.InputType == DeviceInputType.SpatialGrip)
            {
                Debug.Log("spatial grip PositionData: " + inputMapping.PositionData);
                Debug.Log("spatial grip RotationData: " + inputMapping.RotationData);
            }
        }
    }
    

    See Also

    • InputEvents
    • Pointers
    • HandTracking
    • Improve this Doc
    Back to top Generated by DocFX