Toolbar
示例程序 | |
---|---|
说明 | 生成一个工具栏 |
用法
public static int Toolbar(int selected, string[] texts, params GUILayoutOption[] options);
public static int Toolbar(int selected, Texture[] images, params GUILayoutOption[] options);
public static int Toolbar(int selected, GUIContent[] contents, params GUILayoutOption[] options);
public static int Toolbar(int selected, string[] texts, GUIStyle style, params GUILayoutOption[] options);
public static int Toolbar(int selected, Texture[] images, GUIStyle style, params GUILayoutOption[] options);
public static int Toolbar(int selected, GUIContent[] contents, GUIStyle style, params GUILayoutOption[] options);
public static int Toolbar(int selected, string[] texts, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options);
public static int Toolbar(int selected, Texture[] images, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options);
public static int Toolbar(int selected, GUIContent[] contents, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options);
参数
selected
被选中按钮的索引。
texts
显示在工具栏按钮中的文本数组。
images
显示在工具栏按钮中的图片数组。
contents
显示在工具栏按钮中的 GUIContent
数组。
style
(可选)该区域的样式。
options
(可选)用于指定额外的布局属性,该参数将覆盖默认样式。
buttonSize
指明工具栏按钮宽度的计算方式。
示例
private void OnEnable () {
contents = new List<GUIContent> ();
for (int i = 0; i < _count; i++) {
contents.Add (new GUIContent (string.Format ("Button {0}", i)));
}
}
private void OnSceneGUI () {
Handles.BeginGUI ();
_index = GUILayout.Toolbar (_index, contents.ToArray (), "button", GUI.ToolbarButtonSize.FitToContents);
_index = GUILayout.Toolbar (_index, contents.ToArray (), "button", GUI.ToolbarButtonSize.Fixed);
Handles.EndGUI ();
}