Files
hybridclr_unity/Editor/Meta/UnityPluginAssemblyResolver.cs
T
walon f2ee5e7af1 [fix] 修复 UnityPluginAssemblyResolver 搜索依赖dll未检查Plugins外目录的bug
[refactor] 一些重命名 hotfix -> hotUpdate
[refactor] HybridCLRGlobalSettings移除 hotUpdateDllOutputDir、 hybridCLRDataDir、strippedAssemblyDir这三个配置项,改为直接写死
[change] Editor下调用LoadMetadataForAOTAssembly返回成功而不是抛出错误
2022-10-08 12:35:57 +08:00

45 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace HybridCLR.Editor.Meta
{
public class UnityPluginAssemblyResolver : IAssemblyResolver
{
private static readonly HashSet<string> s_ignoreDirs = new HashSet<string>
{
"Editor",
"StreamingAssets",
"Resources",
};
private bool IsPluginDll(string dllPath)
{
var fileOrDirs = new HashSet<string>(dllPath.Split('\\', '/'));
return !fileOrDirs.Intersect(s_ignoreDirs).Any();
}
public string ResolveAssembly(string assemblyName, bool throwExIfNotFind)
{
foreach(var dll in Directory.GetFiles(UnityEngine.Application.dataPath, "*.dll", SearchOption.AllDirectories))
{
if (Path.GetFileNameWithoutExtension(dll) == assemblyName && IsPluginDll(dll))
{
Debug.Log($"plugin:{dll}");
return dll;
}
}
if (throwExIfNotFind)
{
throw new Exception($"resolve assembly:{assemblyName} fail");
}
return null;
}
}
}