MRTK의 입력 상태 액세스 - MRTK2

입력 원본에 연결된 컨트롤러를 반복하여 MRTK의 모든 입력 상태를 직접 쿼리할 수 있습니다. MRTK는 또한 눈, 손, 머리 및 모션 컨트롤러의 위치와 회전에 액세스하는 편리한 방법을 제공합니다.

컨트롤러를 반복하고 클래스를 사용하여 InputRayUtils 입력을 쿼리하는 예제는 InputDataExample 장면을 참조하세요.

예: MRTK의 액세스 위치, 머리 회전, 손, 눈

MRTK의 InputRayUtils 클래스는 손 광선, 헤드 레이, 시선 응시 광선 및 모션 컨트롤러 광선에 액세스하는 편리한 방법을 제공합니다.

스크립트에 다음 네임스페이스를 추가합니다.

using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.Utilities;

샘플 코드:

// Get the head ray
UnityEngine.Ray headRay = InputRayUtils.GetHeadGazeRay();

// Get the right hand ray
if (InputRayUtils.TryGetHandRay(Handedness.Right, out UnityEngine.Ray rightHandRay))
{
    // Right hand ray is available
}
else
{
    // Right hand ray is not available
}

예: 액세스 위치, 장면에서 활성 상태인 모든 6DOF 컨트롤러의 회전

스크립트에 다음 네임스페이스를 추가합니다.

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

샘플 코드:

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

        if (interactionMapping.InputType == DeviceInputType.SpatialGrip)
        {
            Debug.Log("Spatial grip PositionData: " + interactionMapping.PositionData);
            Debug.Log("Spatial grip RotationData: " + interactionMapping.RotationData);
        }
    }
}

추가 정보