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参数

  • label
    Optional label in front of the field.  // 字段前面的可选标签。
  • selectedIndex
    The index of the option the field shows.
       字段选项的索引
  • displayedOptions
    An array with the options shown in the popup.
       弹出菜单选项的数组
  • style
    Optional GUIStyle. // 可选样式
  • options
    An optional list of layout options that specify extra layouting   properties. Any values passed in here will override settings defined by   the style.  See Also: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight
    指定额外布局属性的可选列表。这里传递任意值,将覆盖样式定义的设置。

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


,