#Hololens – Fire Buttons actions with a #XBoxOne Controller

Hello!

Yesterday I wrote on how to connect an XBoxOne controller to a Hololens. Today I’ll share a bit of code on how to interact with the device. The example is simple

Once added the ability of Spatial Mapping in the project, we will activate the display of Visual Mesh when you press button A on the XBoxOne remote control

For example:

 

2017-03-01-holo-xboxone-controller-03

We started with the basics, creating a project vacuum in Unity3D and following these steps

  • Configure project to support HoloLens projects
  • Clean Scene elements
  • Import HoloToolkit package
  • Add
    • HololensCamera
    • SpatialMapping
    • CursorWithFeedback
  • Add Empty element, Managers
    • Add existing scripts
      • Gaze Managers
      • Gaze Stabilizer
      • Input Manager
    • Add new empty script
      • XboxControllerManager

After completion of the project would be similar to the following:

Clipboard02.jpg

Now we see the code required for the “XboxControllerManager” script. We will work on the Update(): check for button A pressed state, and let’s add that state to the DrawVisualMeshes property of the active instance of Spatial Mapping.

clipboard04

Done! This is good enough for a sample, although here it is convenient to study a bit about concepts that handles Unity for the “Inputs” (see references). In this case, in the project properties, we can see the basic settings for projects 3D in Unity in this aspect. And the main class for the States of the buttons on the remote control to access is UnityEngine.Input.

In the next post, when working with a kind of HoloToolkit for control of Xbox, comment the changes needed to make it work properly.

The source of the example source code can be downloaded from link.

Greetings @ Toronto

El Bruno

References

Advertisement

32 comments

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: