UnityEditor枚举选择框

 [MenuItem("Tools/导出关卡数据到客户端工程")]
    static void init()
    {
        EditorWindow window = GetWindow(typeof(uteCopyStageLevelConfig));
        window.position = new Rect(500, 300, 300, 400);
        windowType = WindowType.StageLevelM2C;
        display = CopyType.All;
        window.Show();
    }
     private void OnGUI()
    {
        display = (CopyType)EditorGUI.EnumPopup(
            new Rect(3, 10, position.width - 6, 15),
            "选择导出数据类型:",
            display);
        switch (display)
        {
            case CopyType.One:
                EditorGUI.LabelField(new Rect(0, 50, position.width, 15),
                    "导出方式:",
                   "单个关卡数据导出");
                GUI.Label(new Rect(0, 90, 150, 15), "输入要导出的关卡ID数:");
                idStr = GUI.TextField(new  Rect(150, 90, 50, 15), idStr, 15);
                errorStr = "";
                break;

            case CopyType.All:
                EditorGUI.LabelField(new Rect(0, 50, position.width, 15),
                    "导出方式:",
                    "所有关卡数据导出");
                errorStr = "";
                break;

            default:
                Debug.LogError("Unrecognized Option");
                break;
        }
        if (GUI.Button(new Rect(3, position.height - 25, position.width - 6, 24), "确定导出"))
        {
            switch (display)
            {
                case CopyType.One:
                    if (int.TryParse(idStr, out ID))
                    {
                        errorStr = "";
                        Copy(ID);
                        this.Close();
                    }
                    else
                    {
                        errorStr = "输入的ID错误";
                    }
                    break;
                case CopyType.All:
                    Copy();
                    this.Close();
                    break;
            }

        }
        if (!errorStr.Equals(""))
        {
            GUIStyle titleStyle2 = new GUIStyle();
            titleStyle2.normal.textColor = Color.red;
            GUI.Label(new Rect(100, 150, position.width, 25), errorStr, titleStyle2);

        }
    }

效果图:
UnityEditor枚举选择框_第1张图片

你可能感兴趣的:(Unity,Editor,GUI)