GUI.SelectionGrid

切换到手册
public static int SelectionGrid (Rect position, int selected, string[] texts, int xCount);
public static int SelectionGrid (Rect position, int selected, Texture[] images, int xCount);
public static int SelectionGrid (Rect position, int selected, GUIContent[] content, int xCount);
public static int SelectionGrid (Rect position, int selected, string[] texts, int xCount, GUIStyle style);
public static int SelectionGrid (Rect position, int selected, Texture[] images, int xCount, GUIStyle style);
public static int SelectionGrid (Rect position, int selected, GUIContent[] contents, int xCount, GUIStyle style);

参数

position屏幕上用于网格的矩形。
selected所选网格按钮的索引。
texts要在网格按钮上显示的字符串的数组。
images网格按钮上的纹理的数组。
contents网格按钮的文本、图像和工具提示的数组。
xCount在水平方向上放置的元素个数。除非样式定义了要使用的 fixedWidth,否则将缩放控件以适合显示。
style要使用的样式。如果省略,则使用当前 GUISkinbutton 样式。

返回

int 所选按钮的索引。

描述

创建一个按钮网格。

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); } }