SelectionGrid
Make a grid of buttons.
Read time 4 minutesLast updated 5 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.IMGUIModule
SelectionGrid(Rect, int, string[], int)
Make a grid of buttons.
public static int SelectionGrid(Rect position, int selected, string[] texts, int xCount)
Parameters
Rectangle on the screen to use for the grid.
The index of the selected grid button.
An array of strings to show on the grid buttons.
How many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.
Returns
Type | Description |
|---|---|
| int | The index of the selected button. |
Examples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ public int selGridInt = 0; public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"}; void OnGUI() { // use 2 elements in the horizontal direction selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2); }}
SelectionGrid(Rect, int, Texture[], int)
Make a grid of buttons.
public static int SelectionGrid(Rect position, int selected, Texture[] images, int xCount)
Parameters
Rectangle on the screen to use for the grid.
The index of the selected grid button.
An array of textures on the grid buttons.
How many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.
Returns
Type | Description |
|---|---|
| int | The index of the selected button. |
Examples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ public int selGridInt = 0; public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"}; void OnGUI() { // use 2 elements in the horizontal direction selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2); }}
SelectionGrid(Rect, int, GUIContent[], int)
Make a grid of buttons.
public static int SelectionGrid(Rect position, int selected, GUIContent[] content, int xCount)
Parameters
Rectangle on the screen to use for the grid.
The index of the selected grid button.
How many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.
Returns
Type | Description |
|---|---|
| int | The index of the selected button. |
Examples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ public int selGridInt = 0; public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"}; void OnGUI() { // use 2 elements in the horizontal direction selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2); }}
SelectionGrid(Rect, int, string[], int, GUIStyle)
Make a grid of buttons.
public static int SelectionGrid(Rect position, int selected, string[] texts, int xCount, GUIStyle style)
Parameters
Rectangle on the screen to use for the grid.
The index of the selected grid button.
An array of strings to show on the grid buttons.
How many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.
Returns
Type | Description |
|---|---|
| int | The index of the selected button. |
Examples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ public int selGridInt = 0; public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"}; void OnGUI() { // use 2 elements in the horizontal direction selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2); }}
SelectionGrid(Rect, int, Texture[], int, GUIStyle)
Make a grid of buttons.
public static int SelectionGrid(Rect position, int selected, Texture[] images, int xCount, GUIStyle style)
Parameters
Rectangle on the screen to use for the grid.
The index of the selected grid button.
An array of textures on the grid buttons.
How many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.
Returns
Type | Description |
|---|---|
| int | The index of the selected button. |
Examples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ public int selGridInt = 0; public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"}; void OnGUI() { // use 2 elements in the horizontal direction selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2); }}
SelectionGrid(Rect, int, GUIContent[], int, GUIStyle)
Make a grid of buttons.
public static int SelectionGrid(Rect position, int selected, GUIContent[] contents, int xCount, GUIStyle style)
Parameters
Rectangle on the screen to use for the grid.
The index of the selected grid button.
An array of text, image and tooltips for the grid button.
How many elements to fit in the horizontal direction. The controls will be scaled to fit unless the style defines a fixedWidth to use.
Returns
Type | Description |
|---|---|
| int | The index of the selected button. |
Examples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ public int selGridInt = 0; public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"}; void OnGUI() { // use 2 elements in the horizontal direction selGridInt = GUI.SelectionGrid(new Rect(25, 25, 100, 30), selGridInt, selStrings, 2); }}