2022-09-27 14:57:00 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2022-10-08 12:35:34 +08:00
|
|
|
|
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('\\', '/'));
|
2022-11-18 19:38:21 +08:00
|
|
|
|
return !fileOrDirs.Any(dir => dir.EndsWith("~")) && !fileOrDirs.Intersect(s_ignoreDirs).Any();
|
2022-10-08 12:35:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-27 14:57:00 +08:00
|
|
|
|
public string ResolveAssembly(string assemblyName, bool throwExIfNotFind)
|
|
|
|
|
{
|
|
|
|
|
foreach(var dll in Directory.GetFiles(UnityEngine.Application.dataPath, "*.dll", SearchOption.AllDirectories))
|
|
|
|
|
{
|
2022-10-08 12:35:34 +08:00
|
|
|
|
if (Path.GetFileNameWithoutExtension(dll) == assemblyName && IsPluginDll(dll))
|
2022-09-27 14:57:00 +08:00
|
|
|
|
{
|
2022-10-14 14:47:27 +08:00
|
|
|
|
Debug.Log($"UnityPluginAssemblyResolver.ResolveAssembly:{dll}");
|
2022-09-27 14:57:00 +08:00
|
|
|
|
return dll;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (throwExIfNotFind)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception($"resolve assembly:{assemblyName} fail");
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|