UnityEditor 常用组件

2018-10-19  本文已影响0人  Charles陽

文本

    void OnGUI()
    {
        GUILayout.Label("文本", EditorStyles.boldLabel);
    }
3267959-f263769fc0a25409.png

文本框

    string myString = "文本框123";
    void OnGUI()
    {
        myString = EditorGUILayout.TextField("文本框:", myString);
    }
3267959-a823242cc4e2472e.png

自定义字体

void OnGUI()
    {
        GUIStyle fontStyle = new GUIStyle();
        fontStyle.normal.background = null;    //设置背景填充  
        fontStyle.normal.textColor = Color.red;   //设置字体颜色  
        fontStyle.fontStyle = FontStyle.BoldAndItalic;      // 字体加粗倾斜
        fontStyle.fontSize = 18;       //字体大小  
        GUILayout.Label("自定义字体", fontStyle);     
    }
3267959-6aa7973504df00e4.png

区域输入框

    void OnGUI()
    {
        GUILayout.Label ("留言簿:");
        areaText = GUILayout.TextArea(areaText, GUILayout.Height(40)); 
    }

3267959-cd2ac7c057bf134d.png

密码框

    string password;
    void OnGUI()
    {
        password = EditorGUILayout.PasswordField ("密码", password);
    }
3267959-564f662588bd6e88.png

枚举弹出菜单

SystemLanguage language;
    void OnGUI()
    {
        language = (SystemLanguage)EditorGUILayout.EnumPopup("语言:", language);//枚举弹出菜单
    }
3267959-0d948e1690025b9f.png

开关

    bool test;
    void OnGUI()
    {
        test = EditorGUILayout.Toggle("开关:", test);
    }
3267959-d9d3983a3edc1058.png

页签

int toolbar;
    string[] texts = { "A", "B", "C" };
    void OnGUI()
    {
        toolbar = GUILayout.Toolbar(toolbar,texts);
        switch (toolbar)
        {
        case 0:
            GUILayout.Label("a");
            GUILayout.Label("aa");
            GUILayout.Label("aaa");
            GUILayout.Label("aaaa");
            GUILayout.Label("aaaaa");
            GUILayout.Label("aaaaaa");
            break;
        case 1:
            GUILayout.Label("b");
            GUILayout.Label("bb");
            GUILayout.Label("bbb");
            GUILayout.Label("bbbb");
            GUILayout.Label("bbbbb");
            GUILayout.Label("bbbbbb");
            break;
        case 2:
            GUILayout.Label("c");
            GUILayout.Label("cc");
            GUILayout.Label("ccc");
            GUILayout.Label("cccc");
            GUILayout.Label("ccccc");
            GUILayout.Label("cccccc");
            break;
        }
    }
3267959-088c38671c01568c.png

滑动条

    float slider = 0;
    void OnGUI()
    {
        slider = EditorGUILayout.Slider(slider, 1, 10);
    }
3267959-273883003323669d.png

设置Tag

    private string tagStr;
    void OnGUI()
    {
        tagStr = EditorGUILayout.TagField("Tag:", tagStr,GUILayout.Width(250));
    }
3267959-0b793b68487d8128.png

通知提示

private string notification = "ShowNotification";
    void OnGUI()
    {
        notification = EditorGUILayout.TextField (notification);
        this.ShowNotification (new GUIContent (notification));
    }
3267959-0dc8542ee70f2875.png
上一篇下一篇

猜你喜欢

热点阅读