Header Banner
Next Reality Logo
Next Reality
Augmented & Mixed Reality News, Rumors & Dev Guides
nextreality.mark.png
Apple Snap AR Business Google Instagram | Facebook NFT HoloLens Magic Leap Hands-On Smartphone AR The Future of AR Next Reality 30 AR Glossary ARKit Dev 101 What Is AR? Mixed Reality HoloLens Dev 101 Augmented Reality Hololens How-Tos HoloLens v. Magic Leap v. Meta 2 VR v. AR v. MR

HoloLens Dev 101: Building a Dynamic User Interface, Part 5 (Building the UI Elements)

Sep 27, 2017 05:00 PM
Nov 17, 2017 10:46 PM
3D navigation controls in a virtual environment

Alright, calm down and take a breath! I know the object creation chapter was a lot of code. I will give you all a slight reprieve; this section should be a nice and simple, at least in comparison.

In this series on building dynamic user interfaces, what we are eventually creating is a tool that will appear directly into view on an object that is movable, scalable, or rotatable. It will lag behind the users gaze so it is not always directly in front of the user, which would be annoying. The tool will disappear completely when the user takes their gaze off of the object.

In this lesson, we will build the actual UI elements for our new tools set. We could build something elaborate for our UI system, and while we will likely add some cool behaviors to it, for now, we want to keep it simple. We are just going to build the prefab that will be our base UI for this project.

Find UI Elements

First and foremost, we need a few icons to illustrate movement, scale, and rotation. Fortunately, there is a free asset pack in the Unity store called 139 Vector Icons that has a few such items that will suffice nicely.

Open up the Unity Asset Store Browser and type 139 into the research bar.

HoloLens Dev 101: Building a Dynamic User Interface, Part 5 (Building the UI Elements)

Click the "Download" button, and click it again once it turns into the "Import" button.

Free vector icons collection with 139 material designs for UI use.

When the "Import Unity Package" window appears, you have a few choices here.

  • Click the "Import" button to import them all.
  • Click the "Import" button and when they all import, delete all of them except the files numbered 79-01, 35-01, and 37-01.
  • Click the checkboxes for files 79-01, 35-01, and 37-01 and click "Import."
HoloLens Dev 101: Building a Dynamic User Interface, Part 5 (Building the UI Elements)

Once you have the three needed files downloaded, create a Textures directory and drop them in there.

Create UI Prefab

Now let's start building our UI element.

In the Hierarchy window, click "Create" and select "Create Empty." Then name the newly created object "TransformUITools". Make sure its position is X:0, Y:0, and Z:0.

Inspector panel displaying transformation properties for a 3D object in a software application.

Inside the Textures folder grab the 79-01 file and drag it over to the newly created TransformUITool game object.

Next move 37-01 to the same object. Followed by 35-01.

HoloLens Dev 101: Building a Dynamic User Interface, Part 5 (Building the UI Elements)

Rename 79-01 to Move and set its Transform properties to:

  • Position: X: -0.5, Y:0, Z:0
  • Scale: X: 0.2, Y:0.2, Z: 0.2

Repeat this process for 37-01 , renaming it to Scale and set its coordinates to:

  • Position: X: 0, Y:0, Z:0
  • Scale: X: 0.2, Y:0.2, Z: 0.2
HoloLens Dev 101: Building a Dynamic User Interface, Part 5 (Building the UI Elements)

Finally, rename 35-01 to Rotate and set its position and scale to:

  • Position: X:0.5, Y:0, Z: 0
  • Scale: X:0.2, Y:0.2, Z:0.2

And this is more or less what you should see. Once our position and scale is set for each.

3D modeling interface showing a sphere, cylinder, and transformation tools.

Make Textures into Buttons

For this tool to be successful, we eventually need to interact with the UI elements that should be considered buttons.

In the Inspector, click the "Add Component" button and type box into the search field. Select the "Box Collider" option that appears. In the "Box Collider" component that appears, make its size to:

  • Size X: 2,Y: 2, Z:0.2.
3D modeling workspace in Unity showing geometric shapes and transformation tools.

Click on the "Settings" icon, the little gear in the upper corner of the Box Collider component and select "Copy Component."

Image of a user interface in a graphic design or game development software, showing options for managing components.

Now select the Scale sub-object and, in the Sprite Renderer component, click on the "Settings" icon again. This time, though, click on "Paste Component As New."

Software interface showing options to manage components in a development environment.

Repeat the last step for the "Rotate" button as well.

3D modeling tools and objects in a virtual environment.

Add a Few Finishing Touches

Find your BoundingBoxMat in the root Assets directory. Create a Materials folder and drop it in there.

HoloLens Dev 101: Building a Dynamic User Interface, Part 5 (Building the UI Elements)

With our material still selected, click on the color box to pull up the "Color" window. Let's save our color for the material for easy reference as a preset.

Now go to our "Move" button and select it and click on the "Color" box in the "Sprite Renderer" component. Click on the preset we just created. As you will notice, this color, even with more alpha, will blend too well with our bounding box. Adjust the color to:

  • Color: R: 90, G:152, B:255, A: 229

This seems like a fairly complementary color.

Color selection interface showing two color options with sliders and palettes.

Create a Prefabs folder. Click on the "TranformUITool" object we just finished making the drag and drop it into the Prefabs folder.

3D objects including an egg, a clock face, a cylinder, and directional arrows on a neutral background.

Alright, we have a simple UI element ready to go. Next up, we are going to attach it to the currently viewed object in direct connection to our gaze.

Cover image and screenshots by Jason Odom/Next Reality

You already know how to use your phone. With Gadget Hacks' newsletter, we'll show you how to master it. Each week, we explore features, hidden tools, and advanced settings that give you more control over iOS and Android than most users even know exists.

Sign up for Gadget Hacks Weekly and start unlocking your phone's full potential.

Related Articles

Comments

No Comments Exist

Be the first, drop a comment!