Game Development Reference
In-Depth Information
The main difference between the preceding controls is that you have to pass the
currently selected index value in to the control and it then returns the new value.
The Toolbar when drawn looks as follows:
As stated, you can also pass an array of textures as well and they will be displayed
instead of the text content.
The SelectionGrid control
The SelectionGrid control is a customization of the previous standard Toolbar
control, it is able to arrange the buttons in a grid layout and resize the buttons
appropriately to fill the target area.
In code, SelectionGrid is used in a very similar format to the Toolbar code shown
previously, for example:
private int selectionGridInt ;
private string[] selectionStrings;
Void Start() {
selectionGridInt = 0;
selectionStrings = { "Grid 1", "Grid 2", "Grid 3", "Grid 4" };
}
void OnGUI() {
selectionGridInt = GUI.SelectionGrid(
new Rect(250, 200, 200, 60), selectionGridInt, selectionStrings, 2);
}
The main difference between SelectionGrid and Toolbar in code is that with
SelectionGrid you can specify the number of items in a single row and the control will
automatically lay out the buttons accordingly (unless overridden using GUIStyle ).
The preceding code will result in the following layout:
On their own, they provide a little more flexibility than just using buttons alone.
 
Search WWH ::




Custom Search