当前位置:   article > 正文

Unity Inspector的简单绘制_unity inspector 横线

unity inspector 横线

用到的脚本暂时命名为Test

[CustomEditor(typeof(Test))]
  • 1

重写OnInspectorGUI()函数

public class MyInspector : Editor//继承Editor
{
    public override void OnInspectorGUI()//重写OnInspectorGUI()
    {
        //开始横向布局
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("选择XML路径"))
        {
            //写button执行的函数
            //打开文件  得到Path  Path是个属性   这里未写
             Path = EditorUtility.OpenFilePanel("打开训练XML文件", @"C:\Users\    \Desktop", "xml");
        }
        EditorGUILayout.TextField(Path);
        //结束横向布局
        GUILayout.EndHorizontal();
        //该函数在下方得到下面的样式:选择XML路径按钮和路径的text在“Test”脚本上方
        //反之则相反
        base.OnInspectorGUI();
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

base.OnInspectorGUI()在绘制之后的样式

——————————————分割线————————————————
实现如下效果:
完全展开前

完全展开后

    GUILayout.BeginHorizontal();
    GUILayout.Space(10);
    TrainingPerson_Show = EditorGUILayout.Foldout(TrainingPerson_Show, "Traning Person");
    if( GUILayout.Button("增加",GUILayout.Width(50)))
    {
        AddPerson("new person");
        Xml_Data.XmlList.traningPerson.Add(new Person());
    }
    if (GUILayout.Button("删除",GUILayout.Width(50)))
    {
        TakeAwayPerson();
    Xml_Data.XmlList.traningPerson.RemoveAt(Xml_Data.XmlList.traningPerson.Count-1);
    }
    GUILayout.EndHorizontal();
    if (TrainingPerson_Show)
    {
        List<string> Temp_List = new List<string>();
        for (int i = 0; i <= Xml_Data.XmlList.traningPerson.Count - 1; i++)
        {           
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            Person_Show[i] = EditorGUILayout.Foldout(Person_Show[i], "100" + (i + 1));
            GUILayout.EndHorizontal();

            if (Person_Show[i])
            {
                Person p = new Person();
                GUILayout.BeginHorizontal();
                GUILayout.Space(30);
                EditorGUILayout.PrefixLabel("Person ID");
                p.personID = EditorGUILayout.TextField(Xml_Data.XmlList.traningPerson[i].personID);
                Temp_List.Add(p.personID);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Space(30);
                EditorGUILayout.PrefixLabel("Person Name");
                p.personName = EditorGUILayout.TextField(Xml_Data.XmlList.traningPerson[i].personName);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Space(30);
                EditorGUILayout.PrefixLabel("Person Info");
                p.psrsonInfo = EditorGUILayout.TextField(Xml_Data.XmlList.traningPerson[i].psrsonInfo);
                GUILayout.EndHorizontal();
                Xml_Data.XmlList.traningPerson[i] = p;
                }
            }
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/92978
推荐阅读
相关标签
  

闽ICP备14008679号