Popup, IntPopup

示例程序
说明生成一个可选择单个选项的的弹出菜单

用法

两个方法用法基本一致,除了 IntPopup 需要附加一个 int[] 类型的参数以明确标识每个选项对应的索引。而 Popup 有固定的索引,不需要该参数。

public static int IntPopup(int selectedValue, string[] displayedOptions, int[] optionValues, params GUILayoutOption[] options);

public static int IntPopup(int selectedValue, string[] displayedOptions, int[] optionValues, GUIStyle style, params GUILayoutOption[] options);

public static int IntPopup(int selectedValue, GUIContent[] displayedOptions, int[] optionValues, params GUILayoutOption[] options);

public static int IntPopup(int selectedValue, GUIContent[] displayedOptions, int[] optionValues, GUIStyle style, params GUILayoutOption[] options);

public static int IntPopup(string label, int selectedValue, string[] displayedOptions, int[] optionValues, params GUILayoutOption[] options);

public static int IntPopup(string label, int selectedValue, string[] displayedOptions, int[] optionValues, GUIStyle style, params GUILayoutOption[] options);

public static int IntPopup(GUIContent label, int selectedValue, GUIContent[] displayedOptions, int[] optionValues, params GUILayoutOption[] options);

public static int IntPopup(GUIContent label, int selectedValue, GUIContent[] displayedOptions, int[] optionValues, GUIStyle style, params GUILayoutOption[] options);

参数

label

对应的标签名称。

selectedValue

该区域当前显示的选项对应的索引。

displayedOptions

多个可以选择的选项组成的数组。

optionValues

每个选项对应的索引组成的数组。

style

(可选)由 GUIStyle 类型定义的 GUI 样式。

options

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

示例

public override void OnInspectorGUI () {

		// popup with default indices
		_target.PopupIndex = EditorGUILayout.Popup ("Popup", _target.PopupIndex, _target.Options);
		EditorGUILayout.LabelField ("Popup Index", _target.PopupIndex.ToString ());
	
		// popup with custom indices, defined by _target.OptionValues
		_target.IntPopupIndex = EditorGUILayout.IntPopup (
				"IntPopup",
				_target.IntPopupIndex,
				_target.Options,
				_target.OptionValues
		);
		EditorGUILayout.LabelField ("IntPopup Index", _target.IntPopupIndex.ToString ());

}

编译结果如下:

Popup 的默认索引为 0, 1, 2, 3, ...IntPopup 的索引由一个整型数组确定,本例中中为 1, 7, 8