After a long hiatus, I'm back with more Hololens development! In this tutorial, we will talk about how to add tool tips to holographic objects when you gaze at them. In many scenarios there may be multiple voice and gesture commands that can be used to interact with the object. With the aid of tool tips or popup menus it becomes much easier to make your holographic experiences more user friendly. The first thing to do is create a new game object by right clicking in Hierarchy →Create Empty. Rename this to PopupText. In the Inspector window for this object, click Add Component→Mesh→Text Mesh. This text mesh is where you can program the text to be displayed, the font size, style, etc. Next, create a new folder under Assets called Prefab. This will be the place to store all user created objects (very useful for games) and things like text boxes, prompts, etc. Drag the PopupText object and place it in this folder. You have created your first prefab! Now you can delete this from the Hierarchy. A prefab can be instantiated and destroyed in any script. Learn more about Prefabs here. The prefab settings I used can be found at the end of this tutorial. Instead of modifying the currently existing GazeAction script, let's create a new script called GazePopup in the Scripts folder. We will create a public variable textBoxPrefab of type GameObject to point to the prefab we previously created. We will also create a private variable textBox of type GameObject. This will hold the cloned instantiation of the prefab. This is necessary because we need to make this textbox disappear once the user moves her gaze away from the hologram. Unity does not allow the actual prefab asset to be destroyed (I learnt this the hard way!) I wanted the text popup to appear whenever the user gazed at the hologram so I put the popup instantiation code in the OnFocusEnter function. I positioned it to appear an x-offset away from the object itself. Once the user looks away from the hologram, you need to delete the text popup. This can be done by calling the Destroy method on the cloned instantiation textBox. Pro Tip: Notice how the text popup appears conditionally based on the textPopup boolean value? This is because we don't want to create multiple copies of the prefab in our scene. Take out the if condition and see what happens
Pro Tip 2: To see a richer font quality, increase the size of the font in the prefab and scaling it down. Trial and error will get you the right answer
0 Comments
Leave a Reply. |
Archives
December 2018
Categories
|