Hello!
During the last few months, HoloToolkit has evolved a lot. Some of the changes in the Toolkit make some of my blog samples as non-valid. For example, basic actions such as detecting an AirTap. In today’s post, I’ll quickly explain how to implement the AirTap or Click.
We start with the basics with these steps
- Create a 3D project in Unity3D
- 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 existing scripts
- Add Empty element, HoloCollection
- Add 3D elements
- Cube
- Position, x:0 y:0 z:2
- Rotation, x:0 y:0 z:0
- Scale, x:0.3 y:0.3 z:0.3
- Cube
- Add 3D elements
This is the basic process to create a Hololens project in Unity3D. Now let’s associate a script to the Cube that detects some user actions of the user, such as for example the AirTap. For this example, I will call the script “CubeManager.cs“. This is the source code of the script:
using HoloToolkit.Unity.InputModule; using UnityEngine; public class CubeManager : MonoBehaviour, IInputClickHandler, IInputHandler { public void OnInputClicked(InputClickedEventData eventData) { // AirTap code goes here } public void OnInputDown(InputEventData eventData) { } public void OnInputUp(InputEventData eventData) { } }
To capture AirTaps actions, we need to implement the “IInputClickHandler” interface. In the OnInputClicked(InputClickedEventData eventData) method we can perform actions when the user AirTap on the element. In the same way, if we implement the interface “IInputHandler” we can capture events “Click/Tap Down” and “Click/Tap Up” in an element of our app.
Note: Besides the AirTap action, this example serves to Click action on the Hololens clicker.
IMHO, I find it a much more ‘clean’ way this way of working with events using interfaces. Although there is still a way to go. In my next post, I will show how to work with hands and Hololens, for this sample the approach is not interface driven.
The sample code can be downloaded from GitHub (link)
Greetings @ Toronto
El Bruno
References
- GitHub, HoloToolkit
- GitHub, HoloToolkit Unity
- El Bruno, How to Import the HoloToolkit Unity
- El Bruno, How to place a Hologram using AirTap and HoloToolkit
- El Bruno, Creating a menu with options with HoloToolkit
- El Bruno, Using voice commands to display a menu with HoloToolkit
- El Bruno, How to create a 3D text always visible using HoloToolkit
- El Bruno, How to create a HUD (3D text always visible without HoloToolkit)
- El Bruno, How to detect hands using HoloToolkit
- El Bruno, Windows 10, Xbox One Controller, Bluetooth and some lessons learned
- El Bruno, How to use Fire Buttons actions with an XBoxOne Controller
- El Bruno, Moving and rotating holograms using an XBoxOne Controller
Hello!
I want to detect user interaction(gaze,gesture,voice) in an existing app (Galaxy Explorer) and export them in a file or DB. This code can help me to do what I want?
Thank you,
Elena Matsi
LikeLike
Hi Elena
yes, you can use this code as a base for your request. However, please review the Galaxy Explorer code I think they use a different version of Holotoolkit
Regards
-Bruno
LikeLike