您的位置:首页 > 其它

拿到脚本中变量名,根据变量名名称反向输出

2015-03-02 15:20 162 查看
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Reflection;

public class YYFEasyToGetLV : EditorWindow {

[MenuItem ("GameObject/Window")]

static void AddWindow()
{
Rect wr = new Rect(0,0,500,1000);
YYFEasyToGetLV window = (YYFEasyToGetLV)EditorWindow.GetWindowWithRect(typeof(YYFEasyToGetLV),wr,true,"window name");
window.Show();

}

public GameObject father;
public GameObject[] sons;
public GameObject target;

void OnGUI ()
{
father =  EditorGUILayout.ObjectField("father",father,typeof(GameObject),true) as GameObject;

if(GUILayout.Button("GerLv",GUILayout.Width(200)))
{
this.ShowNotification(new GUIContent("You Have Get The Notification"));

sons = new GameObject[father.transform.childCount];
for(int i = 0;i<sons.Length;i++)
{
sons[i]= father.transform.GetChild(i).gameObject;
}
this.ShowNotification(new GUIContent("This is a Notification"));
}

if(sons!=null)
{
GUILayout.Label("YES");
}else{

}

target =  EditorGUILayout.ObjectField("target",target,typeof(GameObject),true) as GameObject;

if(target!=null)
{

if(target.GetComponent<PathEventListenner>()==null)
{
return;
}

FieldInfo[] members =  target.GetComponent<PathEventListenner>().GetType().GetFields();

for(int i = 0;i<members.Length;i++)
{
GUILayout.Label(members[i].Name);
if(GUILayout.Button(members[i].Name))
{
Debug.Log(members[i].Name);

members[i].SetValue(target.GetComponent<PathEventListenner>() ,sons);

}
}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐