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 !"); }
    改变自己
  • 相关阅读:
    WPF进程之间通讯
    win7切换到classic主题后,控件问题
    How to host win32 in wpf?
    WPF 个人经验总结:需要注意的地方
    ListView 的三种数据绑定方式
    用DebugVIew 跟踪调试WPF
    屏幕变小后,wpf窗口被截掉的问题。
    WPF中DPI 的问题
    css中元素居中总结
    arcmap vba 根据DEM高程值生成Shp高程字段
  • 原文地址:https://www.cnblogs.com/sun-shadow/p/15002710.html
Copyright © 2011-2022 走看看