UnityEditor 常用組件

文本

    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;    //設(shè)置背景填充  
        fontStyle.normal.textColor = Color.red;   //設(shè)置字體顏色  
        fontStyle.fontStyle = FontStyle.BoldAndItalic;      // 字體加粗傾斜
        fontStyle.fontSize = 18;       //字體大小  
        GUILayout.Label("自定義字體", fontStyle);     
    }
3267959-6aa7973504df00e4.png

區(qū)域輸入框

    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

開關(guān)

    bool test;
    void OnGUI()
    {
        test = EditorGUILayout.Toggle("開關(guān):", 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

滑動(dòng)條

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

設(shè)置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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容