EditorGUILayout.EnumPopup 枚舉彈出選擇菜單


http://www.unity蠻牛.com/thread-25490-1-1.html

http://www.unity蠻牛.com/m/Script/EditorGUILayout.EnumPopup.html

EditorGUILayout.EnumPopup 枚舉彈出選擇菜單

 

static function EnumPopup (selected : System.Enum, params options : GUILayoutOption[]) : System.Enum
static function EnumPopup (selected : System.Enum, style : GUIStyle, params options : GUILayoutOption[]) : System.Enum
static function EnumPopup (label : string, selected : System.Enum, params options : GUILayoutOption[]) : System.Enum
static function EnumPopup (label : string, selected : System.Enum, style : GUIStyle, params options : GUILayoutOption[]) : System.Enum
static function EnumPopup (label : GUIContent, selected : System.Enum, params options : GUILayoutOption[]) : System.Enum
static function EnumPopup (label : GUIContent, selected : System.Enum, style : GUIStyle, params options : GUILayoutOption[]) : System.Enum

Parameters參數

  • label
    Optional label in front of the field. // 字段前面的可選標簽。
  • selected
    The enum option the field shows. 
    枚舉顯示字段選項
  • 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

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

返回System.Enum,用戶選擇的枚舉選項。

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.

采用當前選擇的枚舉值作為參數並返回用戶選擇的枚舉值。

EditorGUILayout.EnumPopup 枚舉彈出選擇菜單

Create a primitive depending on the option selected. 
創建一個基本物體,取決於用戶選擇的選項 

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

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM