SelectionGrid

示例程序
说明生成一个选择网格

用法

public static int SelectionGrid(int selected, string[] texts, int xCount, params GUILayoutOption[] options);
public static int SelectionGrid(int selected, Texture[] images, int xCount, params GUILayoutOption[] options);
public static int SelectionGrid(int selected, GUIContent[] content, int xCount, params GUILayoutOption[] options);
public static int SelectionGrid(int selected, string[] texts, int xCount, GUIStyle style, params GUILayoutOption[] options);
public static int SelectionGrid(int selected, Texture[] images, int xCount, GUIStyle style, params GUILayoutOption[] options);
public static int SelectionGrid(int selected, GUIContent[] contents, int xCount, GUIStyle style, params GUILayoutOption[] options);

参数

selected

被选中按钮的索引。

texts

显示在网格按钮中的文本数组。

images

显示在网格按钮中的图片数组。

contents

显示在网格按钮中的 GUIContent 数组。

xCount

网格中一行能显示的按钮数。

style

(可选)该区域的样式。

options

(可选)用于指定额外的布局属性,该参数将覆盖默认样式。

示例

private void OnEnable () {
		contents = new List<GUIContent> ();
	
		for (int i = 0; i < _row; i++) {
				for (int j = 0; j < _col; j++) {
						contents.Add (new GUIContent (string.Format ("Button {0}-{1}", i, j)));
				}
		}
}

private void OnSceneGUI () {
		Handles.BeginGUI ();
	
		_index = GUILayout.SelectionGrid (_index, contents.ToArray (), _col);
	
		Handles.EndGUI ();
}