Пример #1
0
        private void Calculate()
        {
            if (string.IsNullOrEmpty(_searchType))
            {
                return;
            }

            var dll  = Assembly.LoadFile(EditorAssetHelper.GetLibraryDll(AssetHelper.AssemblyCSharp));
            var type = dll.GetType(_searchType);

            if (type == null)
            {
                return;
            }

            var baseType = type;
            var types    = dll.GetTypes();
            var subTypes = new HashSet <Type>();

            foreach (var t in types)
            {
                // 其实这里把自己也算进去了
                if (baseType.IsAssignableFrom(t))
                {
                    subTypes.Add(t);
                }
            }

            CaulateTypes(subTypes, dll);
        }
Пример #2
0
        private void CaulateAll()
        {
            var dll   = Assembly.LoadFile(EditorAssetHelper.GetLibraryDll(AssetHelper.AssemblyCSharp));
            var types = new HashSet <Type>();

            foreach (var type in dll.GetTypes())
            {
                if (type.IsEnum)
                {
                    continue;
                }

                types.Add(type);
            }
            CaulateTypes(types, dll);
        }
Пример #3
0
        private Dictionary <MonoScript, List <FieldInfo> > Calculate()
        {
            var dict         = new Dictionary <MonoScript, List <FieldInfo> >();
            var monoType     = typeof(MonoBehaviour);
            var listType     = typeof(List <>);
            var delegateType = typeof(Delegate);
            var eventType    =
                Assembly.LoadFile(EditorAssetHelper.GetLibraryDll(AssetHelper.AssemblyCSharpfirstpass))
                .GetType("EventDelegate");

            foreach (var findAsset in EditorAssetHelper.FindAssetsPaths(EditorAssetHelper.SearchFilter.Script))
            {
                var script     = AssetDatabase.LoadAssetAtPath <MonoScript>(findAsset);
                var scriptType = script.GetClass();
                if (scriptType != null && scriptType.IsSubclassOf(monoType) && !scriptType.IsNestedAssembly &&
                    scriptType.Assembly.FullName.Contains(AssetHelper.AssemblyCSharpfirstpass))
                {
                    foreach (var fieldInfo in scriptType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
                    {
                        var filedType = fieldInfo.FieldType;
                        if (filedType.IsGenericType && filedType.GetGenericTypeDefinition() == listType)
                        {
                            filedType = filedType.GetGenericArguments()[0];
                        }

                        if (filedType.IsSubclassOf(delegateType) ||
                            (eventType != null && filedType.IsSubclassOf(eventType)))
                        {
                            if (!dict.ContainsKey(script))
                            {
                                dict[script] = new List <FieldInfo>();
                            }

                            dict[script].Add(fieldInfo);
                        }
                    }
                }
            }

            return(dict);
        }