diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs index 0a9f831..a8fe46e 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs @@ -199,9 +199,7 @@ namespace YooAsset.Editor } private List GetEncryptionServicesClassTypes() { - TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom(); - List classTypes = collection.ToList(); - return classTypes; + return EditorTools.GetAssignableTypes(typeof(IEncryptionServices)); } private IEncryptionServices CreateEncryptionServicesInstance() { diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs index 6b7707d..96ecea2 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs @@ -139,8 +139,7 @@ namespace YooAsset.Editor typeof(PackRawFile), }; - TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom(); - var customTypes = collection.ToList(); + var customTypes = EditorTools.GetAssignableTypes(typeof(IPackRule)); types.AddRange(customTypes); for (int i = 0; i < types.Count; i++) { @@ -165,8 +164,7 @@ namespace YooAsset.Editor typeof(CollectSprite) }; - TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom(); - var customTypes = collection.ToList(); + var customTypes = EditorTools.GetAssignableTypes(typeof(IFilterRule)); types.AddRange(customTypes); for (int i = 0; i < types.Count; i++) { @@ -190,8 +188,7 @@ namespace YooAsset.Editor typeof(AddressByGroupAndFileName) }; - TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom(); - var customTypes = collection.ToList(); + var customTypes = EditorTools.GetAssignableTypes(typeof(IAddressRule)); types.AddRange(customTypes); for (int i = 0; i < types.Count; i++) { diff --git a/Assets/YooAsset/Editor/EditorDefine.cs b/Assets/YooAsset/Editor/EditorDefine.cs index 10a5654..202a49f 100644 --- a/Assets/YooAsset/Editor/EditorDefine.cs +++ b/Assets/YooAsset/Editor/EditorDefine.cs @@ -4,10 +4,12 @@ namespace YooAsset.Editor { public class EditorDefine { +#if UNITY_2019_4_OR_NEWER /// /// 停靠窗口类型集合 /// public static readonly Type[] DockedWindowTypes = { typeof(AssetBundleBuilderWindow), typeof(AssetBundleCollectorWindow), typeof(AssetBundleDebuggerWindow), typeof(AssetBundleReporterWindow)}; +#endif } /// diff --git a/Assets/YooAsset/Editor/EditorTools.cs b/Assets/YooAsset/Editor/EditorTools.cs index dd9cd39..dfb004a 100644 --- a/Assets/YooAsset/Editor/EditorTools.cs +++ b/Assets/YooAsset/Editor/EditorTools.cs @@ -1,10 +1,10 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using System.Reflection; using System.Linq; using System.IO; using System.Text; -using System.Text.RegularExpressions; using UnityEngine; using UnityEditor; @@ -15,7 +15,57 @@ namespace YooAsset.Editor /// public static class EditorTools { + static EditorTools() + { + InitAssembly(); + } + #region Assembly +#if UNITY_2019_4_OR_NEWER + private static void InitAssembly() + { + } + + /// + /// 获取带继承关系的所有类的类型 + /// + public static List GetAssignableTypes(System.Type parentType) + { + TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom(parentType); + return collection.ToList(); + } +#else + private static readonly List _cacheTypes = new List(10000); + private static void InitAssembly() + { + Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); + foreach (Assembly assembly in assemblies) + { + List types = assembly.GetTypes().ToList(); + _cacheTypes.AddRange(types); + } + } + + /// + /// 获取带继承关系的所有类的类型 + /// + public static List GetAssignableTypes(System.Type parentType) + { + List result = new List(); + 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; + } +#endif + /// /// 调用私有的静态方法 /// @@ -190,7 +240,7 @@ namespace YooAsset.Editor } #endregion - #region 控制台 + #region EditorConsole private static MethodInfo _clearConsoleMethod; private static MethodInfo ClearConsoleMethod { @@ -551,40 +601,6 @@ namespace YooAsset.Editor } return string.Empty; } - #endregion - - #region 字符串 - /// - /// 是否含有中文 - /// - public static bool IncludeChinese(string content) - { - foreach (var c in content) - { - if (c >= 0x4e00 && c <= 0x9fbb) - return true; - } - return false; - } - - /// - /// 是否是数字 - /// - public static bool IsNumber(string content) - { - if (string.IsNullOrEmpty(content)) - return false; - string pattern = @"^\d*$"; - return Regex.IsMatch(content, pattern); - } - - /// - /// 首字母大写 - /// - public static string Capitalize(string content) - { - return content.Substring(0, 1).ToUpper() + (content.Length > 1 ? content.Substring(1).ToLower() : ""); - } /// /// 截取字符串 @@ -594,7 +610,7 @@ namespace YooAsset.Editor /// 关键字 /// 分割的结果里是否包含关键字 /// 是否使用初始匹配的位置,否则使用末尾匹配的位置 - public static string Substring(string content, string key, bool includeKey, bool firstMatch = true) + private static string Substring(string content, string key, bool includeKey, bool firstMatch = true) { if (string.IsNullOrEmpty(key)) return content; @@ -614,6 +630,7 @@ namespace YooAsset.Editor else return content.Substring(startIndex + key.Length); } + #endregion } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index cc83d60..ee13c2b 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -15,7 +15,7 @@ namespace YooAsset { /// /// 编辑器下的模拟模式 - /// 注意:在初始化的时候自动构建真机运行环境。 + /// 注意:在初始化的时候自动构建真机模拟环境。 /// EditorSimulateMode, @@ -122,7 +122,7 @@ namespace YooAsset _locationServices = parameters.LocationServices; #if !UNITY_EDITOR - if (parameters is EditorPlayModeParameters) + if (parameters is EditorSimulateModeParameters) throw new Exception($"Editor play mode only support unity editor."); #endif