Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

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

EditorGUILayout.EnumPopup

static function EnumPopup(selected: Enum, params options: GUILayoutOption[]): Enum;
static Enum EnumPopup(Enum selected, params GUILayoutOption[] options);
static def EnumPopup(selected as Enum, *options as GUILayoutOption[]) as Enum
static function EnumPopup(selected: Enum, style: GUIStyle, params options: GUILayoutOption[]): Enum;
static Enum EnumPopup(Enum selected, GUIStyle style, params GUILayoutOption[] options);
static def EnumPopup(selected as Enum, style as GUIStyle, *options as GUILayoutOption[]) as Enum
static function EnumPopup(label: string, selected: Enum, params options: GUILayoutOption[]): Enum;
static Enum EnumPopup(string label, Enum selected, params GUILayoutOption[] options);
static def EnumPopup(label as string, selected as Enum, *options as GUILayoutOption[]) as Enum
static function EnumPopup(label: string, selected: Enum, style: GUIStyle, params options: GUILayoutOption[]): Enum;
static Enum EnumPopup(string label, Enum selected, GUIStyle style, params GUILayoutOption[] options);
static def EnumPopup(label as string, selected as Enum, style as GUIStyle, *options as GUILayoutOption[]) as Enum
static function EnumPopup(label: GUIContent, selected: Enum, params options: GUILayoutOption[]): Enum;
static Enum EnumPopup(GUIContent label, Enum selected, params GUILayoutOption[] options);
static def EnumPopup(label as GUIContent, selected as Enum, *options as GUILayoutOption[]) as Enum
static function EnumPopup(label: GUIContent, selected: Enum, style: GUIStyle, params options: GUILayoutOption[]): Enum;
static Enum EnumPopup(GUIContent label, Enum selected, GUIStyle style, params GUILayoutOption[] options);
static def EnumPopup(label as GUIContent, selected as Enum, style as GUIStyle, *options as GUILayoutOption[]) as Enum

Parameters

labelOptional label in front of the field.
selectedThe enum option the field shows.
styleOptional GUIStyle.
optionsAn 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

Enum The enum option that has been selected by the user.

Description

Make an enum popup selection field.

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


Creates a primitive selected by the user.

	// Creates an instance of a primitive depending on the option selected by the user.
	
	enum OPTIONS { 
		CUBE = 0, 
		SPHERE = 1, 
		PLANE = 2
	}
	class EditorGUILayoutEnumPopup extends EditorWindow {
		var op : OPTIONS;
		
		@MenuItem("Examples/Editor GUILayout Enum Popup usage")
		static function Init() {
			var window = GetWindow(EditorGUILayoutEnumPopup);
			window.Show();
		}
		function OnGUI() {
			op = EditorGUILayout.EnumPopup("Primitive to create:", op);
			if(GUILayout.Button("Create"))
				InstantiatePrimitive(op);
		}
		function InstantiatePrimitive(op : OPTIONS) {
			switch (op) {
				case OPTIONS.CUBE:
					var cube : GameObject  = GameObject.CreatePrimitive(PrimitiveType.Cube);
	   				cube.transform.position = Vector3.zero;
	   				break;
				case OPTIONS.SPHERE:
					 var sphere : GameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
					sphere.transform.position = Vector3.zero;
					break;
				case OPTIONS.PLANE:
					var plane : GameObject = GameObject.CreatePrimitive(PrimitiveType.Plane);
					plane.transform.position = Vector3.zero;
					break;
				default:
					Debug.LogError("Unrecognized Option");
					break;
			}
		}
	}