Zugreifen auf den Eingabezustand in MRTK – MRTK2

Es ist möglich, den Zustand aller Eingaben in MRTK direkt abzufragen, indem die Controller durchlaufen werden, die an die Eingabequellen angefügt sind. MRTK bietet auch bequeme Methoden für den Zugriff auf die Position und Drehung von Augen, Händen, Kopf und Bewegungscontroller.

In der InputDataExample-Szene finden Sie ein Beispiel für das Abfragen von Eingaben sowohl über Controller als auch mithilfe der InputRayUtils -Klasse.

Beispiel: Zugriffsposition, Drehung von Kopf, Händen, Augen im MRTK

Die InputRayUtils MRTK-Klasse bietet bequeme Methoden für den Zugriff auf die Strahlen der Hand, des Kopfstrahls, des Blickstrahls und des Bewegungscontrollers.

Fügen Sie Ihrem Skript die folgenden Namespaces hinzu:

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

Beispielcode:

// 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
}

Beispiel: Zugriffsposition, Drehung aller in der Szene aktiven 6DOF-Controller

Fügen Sie Ihrem Skript die folgenden Namespaces hinzu:

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

Beispielcode:

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);
        }
    }
}

Weitere Informationen