mirror of https://github.com/tuyoogame/YooAsset
Merge branch 'main' of ssh://github.com/LiuOcean/YooAsset
commit
9b3839ac0b
|
@ -197,8 +197,9 @@ namespace YooAsset.Editor
|
|||
/// 获取加密类的类型列表
|
||||
/// </summary>
|
||||
private List<Type> GetEncryptionServicesClassTypes()
|
||||
{
|
||||
List<Type> classTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IEncryptionServices));
|
||||
{
|
||||
TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom<IEncryptionServices>();
|
||||
List<Type> classTypes = collection.ToList();
|
||||
return classTypes;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<IPackRule>();
|
||||
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<IFilterRule>();
|
||||
var customTypes = collection.ToList();
|
||||
types.AddRange(customTypes);
|
||||
for (int i = 0; i < types.Count; i++)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 程序集工具类
|
||||
/// </summary>
|
||||
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<string, List<Type>> _cache = new Dictionary<string, List<Type>>();
|
||||
|
||||
static AssemblyUtility()
|
||||
{
|
||||
_cache.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取程序集
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取程序集里的所有类型
|
||||
/// </summary>
|
||||
private static List<Type> 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<Type> types = assembly.GetTypes().ToList();
|
||||
_cache.Add(assemblyName, types);
|
||||
return types;
|
||||
}
|
||||
}
|
||||
|
||||
// 注意:如果没有找到程序集返回空列表
|
||||
UnityEngine.Debug.LogWarning($"Not found assembly : {assemblyName}");
|
||||
return new List<Type>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取带继承关系的所有类的类型
|
||||
/// <param name="parentType">父类类型</param>
|
||||
/// </summary>
|
||||
public static List<Type> GetAssignableTypes(string assemblyName, System.Type parentType)
|
||||
{
|
||||
List<Type> result = new List<Type>();
|
||||
List<Type> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取带属性标签的所有类的类型
|
||||
/// <param name="attributeType">属性类型</param>
|
||||
/// </summary>
|
||||
public static List<Type> GetAttributeTypes(string assemblyName, System.Type attributeType)
|
||||
{
|
||||
List<Type> result = new List<Type>();
|
||||
List<Type> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取带继承关系和属性标签的所有类的类型
|
||||
/// </summary>
|
||||
/// <param name="parentType">父类类型</param>
|
||||
/// <param name="attributeType">属性类型</param>
|
||||
public static List<Type> GetAssignableAttributeTypes(string assemblyName, System.Type parentType, System.Type attributeType, bool checkError = true)
|
||||
{
|
||||
List<Type> result = new List<Type>();
|
||||
List<Type> 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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字符串工具类
|
||||
/// </summary>
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
|
||||
他们帮忙协助解决了很多BUG以及提出了很多宝贵的意见!
|
||||
|
||||
- 黄色幻想
|
||||
|
||||
- 新乞丐王子
|
||||
|
||||
|
||||
- 黄色幻想 (793301844)
|
||||
- 新乞丐王子 (82470934)
|
||||
- Wales-丁 (709501148)
|
||||
- L (401419353)
|
||||
|
||||
|
|
Loading…
Reference in New Issue