MRTK での入力状態へのアクセス — MRTK2
入力ソースにアタッチされるコントローラーを反復処理することで、MRTKにおけるすべての入力の状態を直接照会できます。 MRTKは、目、手、頭、およびモーションコントローラーの位置と回転にアクセスするための便利な方法も提供します。
コントローラーの反復処理とInputRayUtils
クラスの使用の両方により入力を照会する一例については、InputDataExample シーンを参照してください。
例:MRTKにおける頭、手、目の位置と回転へのアクセス
MRTKのInputRayUtils
クラスは、ハンドレイ、ヘッドレイ、視線、モーションコントローラーレイにアクセスするための便利な方法を提供します。
// Get the head ray
var headRay = InputRayUtils.GetHeadGazeRay();
// Get the right hand ray
Ray rightHandRay;
if(InputRayUtils.TryGetHandRay(Handedness.right, rightHandRay))
{
// Right hand ray is available
}
else
{
// Right hand ray is not available
}
例:シーンでアクティブになっているすべての6DOFコントローラーの位置と回転へのアクセス
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);
}
}
}