Legacy Documentation: Version 4.6.2
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorGUILayout.Popup

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function Popup(selectedIndex: int, displayedOptions: string[], params options: GUILayoutOption[]): int;
public static int Popup(int selectedIndex, string[] displayedOptions, params GUILayoutOption[] options);
public static def Popup(selectedIndex as int, displayedOptions as string[], *options as GUILayoutOption[]) as int
public static function Popup(selectedIndex: int, displayedOptions: string[], style: GUIStyle, params options: GUILayoutOption[]): int;
public static int Popup(int selectedIndex, string[] displayedOptions, GUIStyle style, params GUILayoutOption[] options);
public static def Popup(selectedIndex as int, displayedOptions as string[], style as GUIStyle, *options as GUILayoutOption[]) as int
public static function Popup(selectedIndex: int, displayedOptions: GUIContent[], params options: GUILayoutOption[]): int;
public static int Popup(int selectedIndex, GUIContent[] displayedOptions, params GUILayoutOption[] options);
public static def Popup(selectedIndex as int, displayedOptions as GUIContent[], *options as GUILayoutOption[]) as int
public static function Popup(selectedIndex: int, displayedOptions: GUIContent[], style: GUIStyle, params options: GUILayoutOption[]): int;
public static int Popup(int selectedIndex, GUIContent[] displayedOptions, GUIStyle style, params GUILayoutOption[] options);
public static def Popup(selectedIndex as int, displayedOptions as GUIContent[], style as GUIStyle, *options as GUILayoutOption[]) as int
public static function Popup(label: string, selectedIndex: int, displayedOptions: string[], params options: GUILayoutOption[]): int;
public static int Popup(string label, int selectedIndex, string[] displayedOptions, params GUILayoutOption[] options);
public static def Popup(label as string, selectedIndex as int, displayedOptions as string[], *options as GUILayoutOption[]) as int
public static function Popup(label: string, selectedIndex: int, displayedOptions: string[], style: GUIStyle, params options: GUILayoutOption[]): int;
public static int Popup(string label, int selectedIndex, string[] displayedOptions, GUIStyle style, params GUILayoutOption[] options);
public static def Popup(label as string, selectedIndex as int, displayedOptions as string[], style as GUIStyle, *options as GUILayoutOption[]) as int
public static function Popup(label: GUIContent, selectedIndex: int, displayedOptions: GUIContent[], params options: GUILayoutOption[]): int;
public static int Popup(GUIContent label, int selectedIndex, GUIContent[] displayedOptions, params GUILayoutOption[] options);
public static def Popup(label as GUIContent, selectedIndex as int, displayedOptions as GUIContent[], *options as GUILayoutOption[]) as int
public static function Popup(label: GUIContent, selectedIndex: int, displayedOptions: GUIContent[], style: GUIStyle, params options: GUILayoutOption[]): int;
public static int Popup(GUIContent label, int selectedIndex, GUIContent[] displayedOptions, GUIStyle style, params GUILayoutOption[] options);
public static def Popup(label as GUIContent, selectedIndex as int, displayedOptions as GUIContent[], style as GUIStyle, *options as GUILayoutOption[]) as 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.


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