Pregunta

I am using Unity3D, and I have a function which is being called inside of OnGUI to lay out the various gui components of my application. Ordinarily, the labels and buttons are all inside of a certain Rect that I supply, which is centered on the screen.

No problem there... however, what I want to is sometime render the exact same gui elements, which can be dynamic, and thus not just put into a prefabbed texture, into a trapezoid-shaped area off to the side, looking as if that gui were actually on a flat plane, pushed away from the center of the screen, and rotated slightly. All gui buttons that were drawn in the function should still respond normally.

I was rather hoping I could just specify some values in GUI.matrix to map the rectangle to a trapezoid, but my initial exploration seems to show that the gui elements don't appear to use homogenous coordinates, and everything still shows up as rectangular.

Is there any way to do this with Unity, ideally without requiring access to pro-only features?

¿Fue útil?

Solución

Since now Unity3D GUI system isn't very flexible. The new GUI system is one of the features still not released in Unity 4 (we are all waiting for it).

From my point of view it has several problems, particularly:

  • You are forced to layout components using the flow of the code, instead of having a more declarative (or at least a more structured) way to do that.
  • It's quite inefficient (at least one draw call for button).
  • It isn't flexible at all. Add, Remove, Enable/Disable buttons can be come quick a painful operation when the number of buttons increase.

however, what I want to is sometime render the exact same gui elements, which can be dynamic, and thus not just put into a prefabbed texture, into a trapezoid-shaped area off to the side, looking as if that gui were actually on a flat plane, pushed away from the center of the screen, and rotated slightly. All gui buttons that were drawn in the function should still respond normally.

This is quite hard if not impossible to obtain using Unity's GUI classes.

I see 2 possibilities:

  1. Don't use GUI classes to do that. If your GUI is simple enough, you can implement your own (even 3d) buttons using for example:
    • A mesh (a plane or a trapezoid mesh) with a texture for the button background
    • TextMesh for drawing 3D text
    • RayCasting to check if a button has been pressed
  2. Use a library that implements a more advanced GUI system like NGUI

Otros consejos

When I ran into the same problem, I just used normal 3D GameObjects cubes with textures and called OnMouseDown(PC/Mac) or RayCasting(Android/iOS) on them. I guess that's how everyone does it.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top