Generic Input and Pointer Clicks With The Mixed Reality Toolkit

Generic Input and Pointer Clicks 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

  1. Create a new scene
  2. Run the MRTK scene wizard via:
    MixedRealityToolkit/Configure/Apply Scene Settings
  3. Create a Cube
  4. Create a new script named InputHandler
  5. Attach the InputHandler to your Cube
  6. Open the new script in any text editor
  7. Implement the IInputClickHandler and IInputHandler interfaces
  8. Add logic for when Input Click events and Input Up/Down events
using UnityEngine;
using HoloToolkit.Unity.InputModule;

public class InputHandler : MonoBehaviour, IInputClickHandler, IInputHandler
{
    void IInputHandler.OnInputUp(InputEventData eventData)
    {
        Debug.LogFormat("OnInputUp\r\nSource: {0}  SourceId: {1}  InteractionPressKind: {2}",
            eventData.InputSource,
            eventData.SourceId,
            eventData.PressType);
        // Mark the event as used, so it doesn't fall through to other handlers.
        eventData.Use();
    }

    void IInputHandler.OnInputDown(InputEventData eventData)
    {
        Debug.LogFormat("OnInputDown\r\nSource: {0}  SourceId: {1}  InteractionPressKind: {2}",
            eventData.InputSource,
            eventData.SourceId,
            eventData.PressType);
        // Mark the event as used, so it doesn't fall through to other handlers.
        eventData.Use();
    }

    void IInputClickHandler.OnInputClicked(InputClickedEventData eventData)
    {
        Debug.LogFormat("OnInputClicked\r\nSource: {0}  SourceId: {1}  InteractionPressKind: {2}  TapCount: {3}",
            eventData.InputSource,
            eventData.SourceId,
            eventData.PressType,
            eventData.TapCount);
        // Mark the event as used, so it doesn't fall through to other handlers.
        eventData.Use();
    }
}

Next, let’s look at how to get input from a Xbox Controller.

Comments are closed.