Custom in game GUI.

Hello guys, I am starting to mess around with Unity’s GUI tools. I have a particular goal in mind but I am having some difficulties seeing a path.

What I want to do is as follows:

  1. When I right click on an object a context menu will show.
  2. This menu I want to look similar to the Simon game. (Basically a ring of options, could be more than 4.)
  3. Each of the buttons on the ring could have more buttons under them.

The main issue I am having is that the GUI options do not seem to be able to easily handle oddly shaped GUI elements.

Any pointers, or links to advanced GUI tutorials would be helpful.

Thanks,
-Stew

1026109--38082--$GUIProto.png

you can not do that with Unity gui as unity gui always has rectangular buttons.

This is really a job for NGUI or EZGUI where you can use real meshes and mesh colliders for the buttons as thats exactly what you must do.

That or you need to handle the interaction completely outside the UI layer and do it purely mathematical basing on the position of the mouse / touch at the time of interaction

Have you considered using GUITextures. These work independently of the OnGUI function and can be used with custom 2D Textures:

http://docs.unity3d.com/Documentation/ScriptReference/GUITexture.html

They are slightly more tricky to work with than OnGUI, but they may satisfy what you want to achieve.

@dreamora
NGUI and EZGUI both look interesting, but they are too expensive for me at the moment.

@Alastair Callum
With the GUI textures though, they are still limited by Rect, correct?

I may try to see if I can emulate a GUI using some Polygons and RayCasting.

In terms of position yes, such as moving them around the screen you need to update the pixel inset with use of a Rect.

But, GUI Textures also use a pixel boundary collision:

http://docs.unity3d.com/Documentation/ScriptReference/GUIElement.HitTest.html?from=GUITexture

So you can create a new touch hit and check if that hit is within the texture boundary.

[EDIT] Scratch that, that’s me not thinking it through properly. It’s not pixel collision, it is indeed Rect boundary.

You can use PolyContainsPoint to check if a point is inside a given polygon. So you’d set up polygons in the general shape of the buttons.

–Eric

So with the menu i am looking to create, will the GUITexture for each button overlap causing clicking issues. Is there a solid way to maybe check the pixel color of the click and operate the menu that way?

Ok, had a think about this over night. You should be able to use standard OnGUI elements to position your texture2D’s. From there you could use Texture2D.GetPIxel to attain the color of the button pressed…

eg, if color != transparent color == RGB-red/RGB-blue etc

Now, this would only work if the UI buttons where flat in color. and you may need to work out some tolerance for the actual color value of the button and a ‘detected’ value. (+/- in the color spectrum).

Alternatively each button could act as an independent object and send it’s own message back to a UI Controller class (Have a look at SendMessage() )

NEVER use get pixel for such a purpose. It will be 100 to 1000 times slower than doing it mathematically or with PointInPoly

Noted.

Alternatively I guess then you can check the position of the hit relative to the center of the circle. (As you say, mathematically).

[EDIT] Just had a look at NGUI, This looks like your best solution for your UI