Unity 编辑器扩展(九)EditorGUI 和 EditorGUILayout

区分:EditorGUI为固定布局,EditorGUILayout为自动布局

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class TestEditor : EditorWindow
{
    [MenuItem("MyMenu/TestItem")]

    static void Test()
    {
        TestEditor testEditor = (TestEditor)EditorWindow.GetWindow(typeof(TestEditor));
        testEditor.Show();
    }

    float f1;
    float f2;
    string s1;
    string s2;

    void OnGUI()
    {
        if (GUILayout.Button("关闭"))
        {
            this.Close();
        }

        EditorGUI.BeginDisabledGroup(true);

        f1 = EditorGUILayout.FloatField("单精度1", f1);
        s1 = EditorGUILayout.TextField("字符串1", s1);

        EditorGUI.EndDisabledGroup();

        f2 = EditorGUILayout.FloatField("单精度2", f2);
        s2 = EditorGUILayout.TextField("字符串2", s2);
    }
}

Unity 编辑器扩展(九)EditorGUI 和 EditorGUILayout_第1张图片

 

 

你可能感兴趣的:(Unity)