• (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 !"); }
    改变自己
  • 相关阅读:
    时间复杂度,空间复杂度
    冒泡排序,选择排序,插入排序
    redis集群
    redis进阶
    redis常识--基础
    mysql基本操作
    TCP/IP 的介绍
    OSI七层网络模型&TCP&UDP&三握四挥
    DNS
    局域网&广域网
  • 原文地址:https://www.cnblogs.com/sun-shadow/p/15002710.html
Copyright © 2020-2023  润新知