EditorGUILayout.Popup 弹出选择菜单

static function Popup (selectedIndex : int, displayedOptions : string[], params options : GUILayoutOption[]) : int
static function Popup (selectedIndex : int, displayedOptions : string[], style : GUIStyle, params options : GUILayoutOption[]) : int
static function Popup (selectedIndex : int, displayedOptions : GUIContent[], params options : GUILayoutOption[]) : int
static function Popup (selectedIndex : int, displayedOptions : GUIContent[], style : GUIStyle, params options : GUILayoutOption[]) : int
static function Popup (label : string, selectedIndex : int, displayedOptions : string[], params options : GUILayoutOption[]) : int
static function Popup (label : string, selectedIndex : int, displayedOptions : string[], style : GUIStyle, params options : GUILayoutOption[]) : int
static function Popup (label : GUIContent, selectedIndex : int, displayedOptions : GUIContent[], params options : GUILayoutOption[]) : int
static function Popup (label : GUIContent, selectedIndex : int, displayedOptions : GUIContent[], style : GUIStyle, params options : GUILayoutOption[]) : int

Parameters参数

Returns

int - The index of the option that has been selected by the user.

返回整数,用户选择的选项索引。

Description描述

Make a generic popup selection field.

制作一个标准弹出选择字段。

Takes the currently selected index as a parameter and returns the index selected by the user.

采用当前选择的索引作为参数并返回用户选择的索引。

EditorGUILayout.Popup 弹出选择菜单

Create a primitive depending on the option selected.
创建一个基本物体,取决于用户选择的选项

// Creates an instance of a primitive depending on the option selected by the user.

//创建一个基本物体的实例,取决于用户选择的选项

class EditorGUILayoutPopup extends EditorWindow {

	var options : String[] = ["Cube", "Sphere", "Plane"];

	var index : int = 0;



	@MenuItem("Examples/Editor GUILayout Popup usage")

	static function Init() {

		var window = GetWindow(EditorGUILayoutPopup);

		window.Show();

	}

	function OnGUI() {

		index = EditorGUILayout.Popup(index, options);

		if(GUILayout.Button("Create"))

			InstantiatePrimitive();

	}

	function InstantiatePrimitive() {

		switch (index) {

			case 0:

				var cube : GameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);

				cube.transform.position = Vector3.zero;

				break;

			case 1:

				var sphere : GameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);

				sphere.transform.position = Vector3.zero;

				break;

			case 2:

				var plane : GameObject = GameObject.CreatePrimitive(PrimitiveType.Plane);

				plane.transform.position = Vector3.zero;

				break;

			default:

				Debug.LogError("Unrecognized Option");

				break;

		}

	}

}
Page last updated: 2011-7-14