Unity GUI Package + Example

Discuss the Oculus - Unity integration.

Unity GUI Package + Example

Postby boone188 » Thu Oct 31, 2013 3:18 am

Getting GUIs working for VR in Unity seems to be a big cause of pain for people getting started. It is definitely something that needs to be simplified, so I went ahead and created a package to do just that. VRGUI should have you making GUIs in no time. Here is how it works:

1. First you need to import the VRGUI package into your project.
2. Now you need to create a script for your GUI that extends from VRGUI and implements the OnVRGUI method:
Code: Select all
public class ExampleMenu : VRGUI
{
   public override void OnVRGUI()
   {
      GUILayout.BeginArea(new Rect(0f, 0f, Screen.width, Screen.height));
      if (GUILayout.Button("Click Me!"))
      {
         doSomething();
      }
      GUILayout.EndArea();
   }
}

3. Now you need to add this script as a component of your player:
- You can attach it to the camera and it will follow your eyes, or
- You can attach it to your player controller and it will follow your player
4. You can choose to have the GUI displayed on a flat surface or a curved surface (the "Use Curved Surface" field)
5. You can choose where to position the GUI (the "GUI Position" field)
6. You can choose how much to scale the GUI (the "GUI Size" field)
7. You can choose to let the GUI accept mouse and keyboard events (the "Accept Mouse" field)

I have included an example project that shows a very simple implementation of a menu and a HUD. Hope this helps!
You do not have the required permissions to view the files attached to this post.
Last edited by boone188 on Wed Nov 20, 2013 10:19 pm, edited 1 time in total.
boone188
Team Oculus Team Oculus
 
Posts: 225
Joined: Fri Mar 29, 2013 11:34 pm
Location: Irvine, CA

Re: Unity GUI Package + Example

Postby Krisper » Thu Oct 31, 2013 4:13 pm

Really nice, that should help a lot of people.
Krisper
 
Posts: 160
Joined: Fri Mar 29, 2013 2:43 pm
Location: NSW, Australia

Re: Unity GUI Package + Example

Postby jamesj » Fri Nov 01, 2013 12:24 am

I got this working in my project, thanks! I then went to change the values from my .js scripts and ran into trouble. Is it possible to rewrite your example which extends VRGUI to display the GUI in .js? I tried to but ran into problems.
jamesj
 
Posts: 26
Joined: Wed Jul 10, 2013 11:36 am

Re: Unity GUI Package + Example

Postby boone188 » Fri Nov 01, 2013 11:02 am

jamesj wrote:I got this working in my project, thanks! I then went to change the values from my .js scripts and ran into trouble. Is it possible to rewrite your example which extends VRGUI to display the GUI in .js? I tried to but ran into problems.

Oops looks like I left the JS guys out in the cold. I will work on a JS solution tonight!
boone188
Team Oculus Team Oculus
 
Posts: 225
Joined: Fri Mar 29, 2013 11:34 pm
Location: Irvine, CA

Re: Unity GUI Package + Example

Postby jamesj » Fri Nov 01, 2013 11:23 am

boone188 wrote:
jamesj wrote:I got this working in my project, thanks! I then went to change the values from my .js scripts and ran into trouble. Is it possible to rewrite your example which extends VRGUI to display the GUI in .js? I tried to but ran into problems.

Oops looks like I left the JS guys out in the cold. I will work on a JS solution tonight!


Actually I figured out how to change the values in your csharp script from JS. All you have to do is put both VRGUI and the csharp script which creates the GUI into Standard Assets so it compiles first.

Thanks so much, your script is great!
jamesj
 
Posts: 26
Joined: Wed Jul 10, 2013 11:36 am

Re: Unity GUI Package + Example

Postby boone188 » Fri Nov 01, 2013 12:58 pm

jamesj wrote:
boone188 wrote:
jamesj wrote:I got this working in my project, thanks! I then went to change the values from my .js scripts and ran into trouble. Is it possible to rewrite your example which extends VRGUI to display the GUI in .js? I tried to but ran into problems.

Oops looks like I left the JS guys out in the cold. I will work on a JS solution tonight!


Actually I figured out how to change the values in your csharp script from JS. All you have to do is put both VRGUI and the csharp script which creates the GUI into Standard Assets so it compiles first.

Thanks so much, your script is great!

Great to hear! Feel free to make suggestions for changes / additions if you have any.
boone188
Team Oculus Team Oculus
 
Posts: 225
Joined: Fri Mar 29, 2013 11:34 pm
Location: Irvine, CA

Re: Unity GUI Package + Example

Postby DarkJames » Fri Nov 01, 2013 1:44 pm

Hey Boone, this looks great. What sort of license are you using for it?
Can I just use it or do I need to credit or what? :)
Seeing is believing
User avatar
DarkJames
 
Posts: 173
Joined: Mon Sep 23, 2013 9:10 am
Location: Canada

Re: Unity GUI Package + Example

Postby boone188 » Fri Nov 01, 2013 1:52 pm

DarkJames wrote:Hey Boone, this looks great. What sort of license are you using for it?
Can I just use it or do I need to credit or what? :)

No license. Just a free thing on the internet. You can credit me if you want but I don't really care.
boone188
Team Oculus Team Oculus
 
Posts: 225
Joined: Fri Mar 29, 2013 11:34 pm
Location: Irvine, CA

Re: Unity GUI Package + Example

Postby DarkJames » Fri Nov 01, 2013 2:47 pm

Okay cool, thanks for the info :)
Seeing is believing
User avatar
DarkJames
 
Posts: 173
Joined: Mon Sep 23, 2013 9:10 am
Location: Canada

Re: Unity GUI Package + Example

Postby Marbas » Wed Nov 20, 2013 7:03 pm

I got an error when building the test example included in the package. (It works good in the editor)
Im using UnityPro version 4.2.2f1

Code: Select all
Assets/VRGUI/Scripts/VRGUI.cs(2,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference?

It builds fine when disabling line 2:

Code: Select all
using UnityEngine;
//using UnityEditor;
using System.Collections;

But then the menu and mouse pointer don't show.
Any idea how to fix this?

Thanks for sharing!

EDIT: Silly me, I was looking in the wrong direction. I expected the "click me" button to follow my eyes.
However, I still need to disable line2 to build the example scene.
User avatar
Marbas
 
Posts: 105
Joined: Fri Mar 29, 2013 12:37 pm

Re: Unity GUI Package + Example

Postby boone188 » Wed Nov 20, 2013 7:49 pm

Oops looks like an unneeded import statement snuck in there. I'll fix it and update the package. Thanks for pointing that out
boone188
Team Oculus Team Oculus
 
Posts: 225
Joined: Fri Mar 29, 2013 11:34 pm
Location: Irvine, CA

Re: Unity GUI Package + Example

Postby saarwii » Sat Nov 23, 2013 9:54 am

this is a great tool! thank you for the great work!

i just got i to work but i'm having one problem. Im using the code in this thread and i attached it to the OVRCameraController. But it does not follow eyes when i look up or down, just when i look left and right. what am i missing?
saarwii
 
Posts: 22
Joined: Mon Aug 05, 2013 5:27 am

Re: Unity GUI Package + Example

Postby boone188 » Sat Nov 23, 2013 12:43 pm

saarwii wrote:this is a great tool! thank you for the great work!

i just got i to work but i'm having one problem. Im using the code in this thread and i attached it to the OVRCameraController. But it does not follow eyes when i look up or down, just when i look left and right. what am i missing?

If you want a GUI to follow the eyes in every direction, you should attach it to one of the OVRCameras. Typically people use "CameraRight".
boone188
Team Oculus Team Oculus
 
Posts: 225
Joined: Fri Mar 29, 2013 11:34 pm
Location: Irvine, CA

Re: Unity GUI Package + Example

Postby saarwii » Sat Nov 23, 2013 2:54 pm

thanks! should have looked at your example project first :) everything was there
saarwii
 
Posts: 22
Joined: Mon Aug 05, 2013 5:27 am

Re: Unity GUI Package + Example

Postby LightYarn » Sat Nov 23, 2013 11:29 pm

Thank you! This really helps me with my project! :)
LightYarn
 
Posts: 3
Joined: Mon Oct 28, 2013 11:55 pm

Re: Unity GUI Package + Example

Postby jamesj » Fri Dec 06, 2013 1:53 pm

I have accept mouse input checked but I can't seem to click any of my buttons! Id also like to add "look to select" type interactions with my menu elements in the VRGUI but I am not sure how to go about it with VRGUI.

I tried to skip this problem by rendering my buttons to boxes, and putting them in front of the curved plane. Im shooting a ray out from the oculus cameras and detecting collisions with the boxes. This works except that the texture on the plane covers up the buttons, making them hard to see (both are somewhat transparent). I can't get the buttons to show up OVER the UI, and I can't get the buttons to work INSIDE the UI.
jamesj
 
Posts: 26
Joined: Wed Jul 10, 2013 11:36 am

Re: Unity GUI Package + Example

Postby boone188 » Fri Dec 06, 2013 11:16 pm

jamesj wrote:I have accept mouse input checked but I can't seem to click any of my buttons! Id also like to add "look to select" type interactions with my menu elements in the VRGUI but I am not sure how to go about it with VRGUI.

I tried to skip this problem by rendering my buttons to boxes, and putting them in front of the curved plane. Im shooting a ray out from the oculus cameras and detecting collisions with the boxes. This works except that the texture on the plane covers up the buttons, making them hard to see (both are somewhat transparent). I can't get the buttons to show up OVER the UI, and I can't get the buttons to work INSIDE the UI.


Strange that the mouse input wouldn't work. Did the demo scene work? I can definitely add look-control. That was something I planned on adding from the beginning. If you could elaborate on how you would like it implemented I would appreciate it.
boone188
Team Oculus Team Oculus
 
Posts: 225
Joined: Fri Mar 29, 2013 11:34 pm
Location: Irvine, CA

Re: Unity GUI Package + Example

Postby jamesj » Sun Dec 08, 2013 12:31 pm

I ended up implementing my own look control. I think stuff is weird for me since I'm including your c# scripts but using JS to interact with them. I just cast a ray from the camera to the curved UI plane to figure out which buttons the user was looking at. Never did figure out why mouse click didn't work.
jamesj
 
Posts: 26
Joined: Wed Jul 10, 2013 11:36 am

Re: Unity GUI Package + Example

Postby boone188 » Sun Dec 08, 2013 9:26 pm

jamesj wrote:I ended up implementing my own look control. I think stuff is weird for me since I'm including your c# scripts but using JS to interact with them. I just cast a ray from the camera to the curved UI plane to figure out which buttons the user was looking at. Never did figure out why mouse click didn't work.

That's cool. I will still probably implement this at some point.
boone188
Team Oculus Team Oculus
 
Posts: 225
Joined: Fri Mar 29, 2013 11:34 pm
Location: Irvine, CA

Re: Unity GUI Package + Example

Postby jamesj » Mon Dec 09, 2013 12:24 pm

Cool! Let me know if you update the script.
jamesj
 
Posts: 26
Joined: Wed Jul 10, 2013 11:36 am


Return to “Unity Integration”


Who is online

Users browsing this forum: vferguson, weasel47 and 4 guests