赞
踩
用到的脚本暂时命名为Test
[CustomEditor(typeof(Test))]
重写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();
}
}
——————————————分割线————————————————
实现如下效果:
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;
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。