diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs index 46ee149..41e1272 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs @@ -197,8 +197,9 @@ namespace YooAsset.Editor /// 获取加密类的类型列表 /// private List GetEncryptionServicesClassTypes() - { - List classTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IEncryptionServices)); + { + TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom(); + List classTypes = collection.ToList(); return classTypes; } diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs index 43c8ca5..620dffb 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using UnityEngine; using UnityEditor; @@ -110,7 +111,9 @@ namespace YooAsset.Editor typeof(PackGrouper), typeof(PackRawFile), }; - var customTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IPackRule)); + + TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom(); + var customTypes = collection.ToList(); types.AddRange(customTypes); for (int i = 0; i < types.Count; i++) { @@ -134,7 +137,9 @@ namespace YooAsset.Editor typeof(CollectPrefab), typeof(CollectSprite) }; - var customTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IFilterRule)); + + TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom(); + var customTypes = collection.ToList(); types.AddRange(customTypes); for (int i = 0; i < types.Count; i++) { diff --git a/Assets/YooAsset/Runtime/Utility/YooUtility.cs b/Assets/YooAsset/Runtime/Utility/YooUtility.cs index 6dea756..a748918 100644 --- a/Assets/YooAsset/Runtime/Utility/YooUtility.cs +++ b/Assets/YooAsset/Runtime/Utility/YooUtility.cs @@ -3,147 +3,10 @@ using System.Collections; using System.Collections.Generic; using System.Text; using System.IO; -using System.Linq; using System.Security.Cryptography; -using System.Diagnostics; -using System.Reflection; namespace YooAsset { - /// - /// 程序集工具类 - /// - internal static class AssemblyUtility - { - public const string YooAssetAssemblyName = "YooAsset"; - public const string YooAssetAssemblyEditorName = "YooAsset.Editor"; - public const string UnityDefaultAssemblyName = "Assembly-CSharp"; - public const string UnityDefaultAssemblyEditorName = "Assembly-CSharp-Editor"; - - - private static readonly Dictionary> _cache = new Dictionary>(); - - static AssemblyUtility() - { - _cache.Clear(); - } - - /// - /// 获取程序集 - /// - public static Assembly GetAssembly(string assemblyName) - { - Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); - foreach (Assembly assembly in assemblies) - { - if (assembly.GetName().Name == assemblyName) - return assembly; - } - return null; - } - - /// - /// 获取程序集里的所有类型 - /// - private static List GetTypes(string assemblyName) - { - if (_cache.ContainsKey(assemblyName)) - return _cache[assemblyName]; - - Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); - foreach (Assembly assembly in assemblies) - { - if (assembly.GetName().Name == assemblyName) - { - List types = assembly.GetTypes().ToList(); - _cache.Add(assemblyName, types); - return types; - } - } - - // 注意:如果没有找到程序集返回空列表 - UnityEngine.Debug.LogWarning($"Not found assembly : {assemblyName}"); - return new List(); - } - - /// - /// 获取带继承关系的所有类的类型 - /// 父类类型 - /// - public static List GetAssignableTypes(string assemblyName, System.Type parentType) - { - List result = new List(); - List cacheTypes = GetTypes(assemblyName); - for (int i = 0; i < cacheTypes.Count; i++) - { - Type type = cacheTypes[i]; - - // 判断继承关系 - if (parentType.IsAssignableFrom(type)) - { - if (type.Name == parentType.Name) - continue; - result.Add(type); - } - } - return result; - } - - /// - /// 获取带属性标签的所有类的类型 - /// 属性类型 - /// - public static List GetAttributeTypes(string assemblyName, System.Type attributeType) - { - List result = new List(); - List cacheTypes = GetTypes(assemblyName); - for (int i = 0; i < cacheTypes.Count; i++) - { - System.Type type = cacheTypes[i]; - - // 判断属性标签 - if (Attribute.IsDefined(type, attributeType)) - { - result.Add(type); - } - } - return result; - } - - /// - /// 获取带继承关系和属性标签的所有类的类型 - /// - /// 父类类型 - /// 属性类型 - public static List GetAssignableAttributeTypes(string assemblyName, System.Type parentType, System.Type attributeType, bool checkError = true) - { - List result = new List(); - List cacheTypes = GetTypes(assemblyName); - for (int i = 0; i < cacheTypes.Count; i++) - { - Type type = cacheTypes[i]; - - // 判断属性标签 - if (Attribute.IsDefined(type, attributeType)) - { - // 判断继承关系 - if (parentType.IsAssignableFrom(type)) - { - if (type.Name == parentType.Name) - continue; - result.Add(type); - } - else - { - if(checkError) - throw new Exception($"class {type} must inherit from {parentType}."); - } - } - } - return result; - } - } - /// /// 字符串工具类 /// diff --git a/Docs/Contributor.md b/Docs/Contributor.md index 0a3cb28..a4447f0 100644 --- a/Docs/Contributor.md +++ b/Docs/Contributor.md @@ -4,9 +4,8 @@ 他们帮忙协助解决了很多BUG以及提出了很多宝贵的意见! -- 黄色幻想 - -- 新乞丐王子 - - +- 黄色幻想 (793301844) +- 新乞丐王子 (82470934) +- Wales-丁 (709501148) +- L (401419353)