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 !"); }
    改变自己
  • 相关阅读:
    缩放图片
    Volley下载图片存放在data/data下 networkImageView lrucache
    类实现Parcelable接口在Intent中传递
    基本控件设置边角图片 drawableleft
    屏幕全屏之类的问题
    关于点击按钮分享
    万能适配器的一些问题
    自定义控件高级
    Fragment 生命周期 全局变量的声明位置
    GridView
  • 原文地址:https://www.cnblogs.com/sun-shadow/p/15002710.html
Copyright © 2011-2022 走看看