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.
- Create a new scene
- Run the MRTK scene wizard via:
MixedRealityToolkit/Configure/Apply Scene Settings
- Create an empty
GameObject
- Rename the
GameObject
toMotionControllerHandler
- Create a new script named
MotionControllerHandler
- Attach the new
MotionControllerHandler
script to yourMotionControllerHandler
GameObject
- Open the new script in any text editor
- Implement the
ISelectHandler
,IControllerTouchpadHandler
,ISourcePositionHandler
, andISourceRotationHandler
interfaces - 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); } }