您的位置:首页 > 移动开发 > Unity3D

unity 反射编辑器

2016-02-25 11:07 701 查看
using UnityEngine;

using System.Collections.Generic;

using UnityEditor;

using System;

using System.Linq;

public class ReflectionEditor : Editor

{

    #region 继承链

    [MenuItem("Reflection/向上的继承链")]

    static void 向上的继承链()

    {

        for (int i = 0; i < Selection.objects.Length; i++)

        {

            var monoScript = Selection.objects[i] as MonoScript;

            if (monoScript == null)

                continue;

            var type = monoScript.GetClass();

            Debug.Log(type + " 向上的继承链 : ");

            IEnumerable<Type> types = type.Assembly.GetTypes().Where(item => item.IsAssignableFrom(type) && item != type);

            foreach (Type t in types)

                Debug.Log(t);

        }

    }

    [MenuItem("Reflection/向下的继承链")]

    static void 向下的继承链()

    {

        for(int i = 0; i < Selection.objects.Length; i++)

        {

            var monoScript = Selection.objects[i] as MonoScript;

            if (monoScript == null)

                continue;

            var type = monoScript.GetClass();

            Debug.Log(type + " 向下的继承链 : ");

            IEnumerable<Type> types = type.Assembly.GetTypes().Where(item => type.IsAssignableFrom(item) && item != type);

            foreach (Type t in types)

                Debug.Log(t);

        }

    }

    #endregion

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