Game Development Reference
In-Depth Information
The text mesh isn't well documented and is only here for reference;
as we delve deeper into the new UI system, we will find much better
ways of achieving this.
Common control features
The legacy GUI system does also have some features for controlling flow, control
selection, and targeted behavior. When it was introduced in Unity V2, it was a huge
step up from the previous component-based system.
Grouping controls
The legacy GUI allow you to group controls together on the screen, making all
positions for the group relative to the group's position. This means that if you started
a group at position X 50 and Y 50, then all child control positions within the group
would start at 50,50 when they define their position as 0,0.
Like the ScrollView control, each group has a beginning and an end to define the
scope of all the controls within the group, for example:
void OnGUI() {
//Start a group at position 50, 50. 150 width and 60 height
GUI.BeginGroup(new Rect (50,50,150,60));
//Draw a label with a 10, 10 offset in the group
GUI.Label(new Rect (10, 10, 100, 30), "Label in a Group");
GUI.EndGroup();
}
Here the label is drawn within the group bounds, and as the group starts at X 50,
the Labels screen position will be at X 60 (50 + 10) . Anything positioned or
overflowing the group's bounds will not be drawn.
The group, like other controls, can also specify content within the group as text or a
texture with appropriate GUIStyles .
What is odd is that unlike the rest of the controls, if you specify text
content in the function, the default color of text is white, whereas if you
specify text in the content parameter for the BeginGroup function, the
text in the group is black by default. It's also left justified instead
of centered.
Additionally, by default the group does not support Rich Text
Formatting unlike the other controls, so you will need to apply
GUIStyle to change that.
 
Search WWH ::




Custom Search