zoukankan      html  css  js  c++  java
  • (unity小工具)C# 获取选择的Gameobject对象被引用的类名和字段名

    拖动到父节点的gameobject,太多后不好找。添加打印,获取类名和字段名。




    [MenuItem("GameObject/获取对象引用的类名和字段名", false, 32)] public static void GetCurParentRefName() { Transform selectChild = Selection.activeTransform; if (selectChild == null) { Debug.LogError("You must select Obj first!"); return; } if (selectChild != null) { int id = selectChild.GetInstanceID(); int parentCount = 0; while (selectChild.parent != null) { parentCount++; selectChild = selectChild.parent; var coms = selectChild.GetComponents<Component>(); foreach (Component v in coms) { if (!(v is MonoBehaviour)) { continue; } System.Type clsType = v.GetType(); var properties = clsType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (System.Reflection.FieldInfo info in properties) { var attributes = info.GetCustomAttributes(typeof(System.ObsoleteAttribute), true); if (attributes.Length > 0) { continue; } var realValue = info.GetValue(v) as UnityEngine.Component; if (realValue && realValue.transform) { if (realValue.transform.GetInstanceID() == id) { Debug.Log(string.Format("向上层数:{0}|节点名:{1}|类名:{2}|字段名:{3}", parentCount, selectChild.name, clsType.Name, info.Name)); return; } } } } } } Debug.Log("not find !"); }
    改变自己
  • 相关阅读:
    项目管理
    开源视频会议bigbluebutton开发(1)——初始化安装以及配置
    oracle休系统结构
    Tomcat上安装配置Axis
    锁表头
    文件复制三种方法
    程序员技术练级攻略
    Linux (RHEL 5.4)下安装 Oracle 10g R2
    Android 学习资料收集汇总
    WAS61安装调整和应用部署.doc
  • 原文地址:https://www.cnblogs.com/sun-shadow/p/15002710.html
Copyright © 2011-2022 走看看