Game Development Reference
In-Depth Information
Toolbar panels
The basic GUI controls also come with some very basic automatic layout panels:
the first handles an arrangement of buttons, however these buttons are grouped
and only one can be selected at a time.
As with other controls, the style of the button can be altered using a GUIStyles
definition, including fixing the width of the buttons and spacing.
There are two layout options available, these are:
• The Toolbar control
• The Selection grid control
The Toolbar control
The Toolbar control arranges buttons in a horizontal pattern (vertical is
not supported).
Note that it is possible to fake a vertical toolbar by using a selection
grid with just one item per row. See the Selection grid section later
in this chapter for more details.
As with other controls, the Toolbar returns the index of the currently selected button
in the toolbar. The buttons are also the same as the base button control so it also
offers options to support either text or images for the button content.
The RepeatButton control however is not supported.
To implement the toolbar, you specify an array of the content you wish to display in
each button and the integer value that controls the selected button, as follows:
private int toolbarInt;
private string[] toolbarStrings ;
Void Start() {
toolbarInt = 0;
toolbarStrings = { "Toolbar1", "Toolbar2", "Toolbar3" };
}
void OnGUI() {
toolbarInt = GUI.Toolbar(new Rect(25, 200, 200, 30),
toolbarInt, toolbarStrings);
}
 
Search WWH ::




Custom Search