Detecting Input Sources 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
- Create a new scene
- Run the MRTK scene wizard via:
MixedRealityToolkit/Configure/Apply Scene Settings
- Create an empty
GameObject
- Rename the
GameObject
toInputSourceHandler
- Attach a
SetGlobalListener
component to theInputSourceHander
GameObject
- Create a new script named
InputSourceHandler
- Attach the
InputSourceHandler
to yourInputSourceHander
GameObject
- Open the new script in your preferred text editor
- Implement the
ISourceStateHandler
interface after theMonobehaviour
class inheritance declaration - Add logic for handling source detection and loss
using UnityEngine; using HoloToolkit.Unity.InputModule; public class InputSourceDetectionHandler : MonoBehaviour, ISourceStateHandler { public void OnSourceDetected(SourceStateEventData eventData) { Debug.LogFormat("OnSourceDetected\r\nSource: {0} SourceId: {1}", eventData.InputSource, eventData.SourceId); // Mark the event as used, so it doesn't fall through to other handlers. eventData.Use(); } public void OnSourceLost(SourceStateEventData eventData) { Debug.LogFormat("OnSourceLost\r\nSource: {0} SourceId: {1}", eventData.InputSource, eventData.SourceId); // Mark the event as used, so it doesn't fall through to other handlers. eventData.Use(); } }
Next, let’s get some Focus.