Motion Controller Input With The Mixed Reality Toolkit

Motion Controller Input With The Mixed Reality Toolkit

What you’ll need

If you haven’t done so already, be sure you’ve properly setup your development environment and you’ve imported the Mixed Reality Toolkit into your project.  You’ll also need to be familiar with the Unity Editor and its interface controls.  If you are not, there is a great tutorial series to get you started.

Getting Started

Note: Only availible for the UWP Build Target.

  1. Create a new scene
  2. Run the MRTK scene wizard via:
    MixedRealityToolkit/Configure/Apply Scene Settings
  3. Create an empty GameObject
  4. Rename the GameObject to MotionControllerHandler
  5. Create a new script named MotionControllerHandler
  6. Attach the new MotionControllerHandler script to your MotionControllerHandler GameObject
  7. Open the new script in any text editor
  8. Implement the ISelectHandlerIControllerTouchpadHandlerISourcePositionHandler, and ISourceRotationHandlerinterfaces
  9. Add logic for each event
using UnityEngine;
using HoloToolkit.Unity.InputModule;

public class MotionControllerHandler : MonoBehaviour, ISelectHandler, IControllerTouchpadHandler, ISourcePositionHandler, ISourceRotationHandler
{
    void IControllerInputHandler.OnInputPositionChanged(InputPositionEventData eventData)
    {
        Debug.LogFormat("OnRotationChanged\r\nSource: {0}  SourceId: {1}  Input Position: {2}",
            eventData.InputSource, eventData.SourceId, eventData.Position);
    }

    void ISelectHandler.OnSelectPressedAmountChanged(SelectPressedEventData eventData)
    {
        Debug.LogFormat("OnRotationChanged\r\nSource: {0}  SourceId: {1}  Select Press Amount: {2}",
            eventData.InputSource, eventData.SourceId, eventData.PressedAmount);
    }

    void IControllerTouchpadHandler.OnTouchpadTouched(InputEventData eventData)
    {
        Debug.LogFormat("OnRotationChanged\r\nSource: {0}  SourceId: {1}  InteractionPressKind: {2}",
            eventData.InputSource, eventData.SourceId, eventData.PressType);
    }

    void IControllerTouchpadHandler.OnTouchpadReleased(InputEventData eventData)
    {
        Debug.LogFormat("OnRotationChanged\r\nSource: {0}  SourceId: {1}  InteractionPressKind: {2}",
            eventData.InputSource, eventData.SourceId, eventData.PressType);
    }

    void ISourcePositionHandler.OnPositionChanged(SourcePositionEventData eventData)
    {
        Debug.LogFormat("OnRotationChanged\r\nSource: {0}  SourceId: {1}  Pointer Rotation: {2}  Grip Rotation {3}",
            eventData.InputSource, eventData.SourceId, eventData.PointerPosition, eventData.GripPosition);
    }

    void ISourceRotationHandler.OnRotationChanged(SourceRotationEventData eventData)
    {
        Debug.LogFormat("OnRotationChanged\r\nSource: {0}  SourceId: {1}  Pointer Rotation: {2}  Grip Rotation {3}",
            eventData.InputSource, eventData.SourceId, eventData.PointerRotation, eventData.GripRotation);
    }
}
Comments are closed.