[fix] 修复 UnityPluginAssemblyResolver 搜索依赖dll未检查Plugins外目录的bug

[refactor] 一些重命名 hotfix -> hotUpdate
[refactor] HybridCLRGlobalSettings移除 hotUpdateDllOutputDir、 hybridCLRDataDir、strippedAssemblyDir这三个配置项,改为直接写死
[change] Editor下调用LoadMetadataForAOTAssembly返回成功而不是抛出错误
main
walon 2022-10-08 12:35:34 +08:00
parent 8eb94be37e
commit f2ee5e7af1
8 changed files with 54 additions and 22 deletions

View File

@ -30,7 +30,7 @@ namespace HybridCLR.Editor.Commands
public static void CompileDll(BuildTarget target) public static void CompileDll(BuildTarget target)
{ {
CompileDll(SettingsUtil.GetHotFixDllsOutputDirByTarget(target), target); CompileDll(SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target), target);
} }
[MenuItem("HybridCLR/CompileDll/ActiveBuildTarget", priority = 100)] [MenuItem("HybridCLR/CompileDll/ActiveBuildTarget", priority = 100)]

View File

@ -33,13 +33,4 @@ public class HybridCLRGlobalSettings : ScriptableObject
[Header("MethodBridge泛型搜索迭代次数")] [Header("MethodBridge泛型搜索迭代次数")]
public int maxMethodBridgeGenericIteration = 4; public int maxMethodBridgeGenericIteration = 4;
[Header("热更新dll输出目录相对HybridCLRData目录")]
public string hotUpdateDllOutputDir = "HotUpdateDlls";
[Header("HybridCLRData目录相对工程目录")]
public string hybridCLRDataDir = "HybridCLRData";
[Header("裁剪后的AOT assembly输出目录")]
public string strippedAssemblyDir = "AssembliesPostIl2CppStrip";
} }

View File

@ -29,8 +29,8 @@ namespace HybridCLR.Editor.Installer
$"你所在项目的Unity版本可以与il2cpp_plus版本:{m_Controller.Il2CppBranch} 不一样。\n" $"你所在项目的Unity版本可以与il2cpp_plus版本:{m_Controller.Il2CppBranch} 不一样。\n"
+ $"如果你的Unity的版本号 >= {minCompatibleVersion}, 可以直接安装。\n" + $"如果你的Unity的版本号 >= {minCompatibleVersion}, 可以直接安装。\n"
+ $"如果你的Unity的版本号 < {minCompatibleVersion}, \n" + $"如果你的Unity的版本号 < {minCompatibleVersion}, \n"
+ $"由于安装HybridCLR时需要从il2cpp_plus对应版本{m_Controller.Il2CppBranch}而不是你项目版本拷贝il2cpp目录\n" + $"由于安装HybridCLR时需要从il2cpp_plus兼容版本{m_Controller.Il2CppBranch}而不是你项目版本拷贝il2cpp目录\n"
+ $"你必须同时安装相应版本 {m_Controller.Il2CppBranch} 才能完成安装", EditorStyles.wordWrappedLabel); + $"你必须同时安装兼容版本 {m_Controller.Il2CppBranch} 才能完成安装", EditorStyles.wordWrappedLabel);
EditorGUILayout.LabelField("=============================================="); EditorGUILayout.LabelField("==============================================");
GUILayout.Space(10f); GUILayout.Space(10f);
@ -38,7 +38,7 @@ namespace HybridCLR.Editor.Installer
EditorGUILayout.LabelField($"安装状态:{(m_Controller.HasInstalledHybridCLR() ? "" : "")}", EditorStyles.boldLabel); EditorGUILayout.LabelField($"安装状态:{(m_Controller.HasInstalledHybridCLR() ? "" : "")}", EditorStyles.boldLabel);
GUILayout.Space(5f); GUILayout.Space(5f);
EditorGUILayout.LabelField($"当前Unity版本: {Application.unityVersion}匹配的il2cpp_plus分支: {m_Controller.Il2CppBranch}"); EditorGUILayout.LabelField($"当前Unity版本: {Application.unityVersion}匹配的il2cpp_plus分支: {m_Controller.Il2CppBranch}");
GUISelectUnityDirectory($"il2cpp_plus分支对应Unity版本的il2cpp路径", "Select"); GUISelectUnityDirectory($"il2cpp_plus分支对应Unity兼容版本的il2cpp路径", "Select");
GUILayout.Space(10f); GUILayout.Space(10f);
GUIInstallButton("安装最新HybridCLR插件代码到本项目", "安装", InitHybridCLR); GUIInstallButton("安装最新HybridCLR插件代码到本项目", "安装", InitHybridCLR);
EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical();

View File

@ -11,11 +11,24 @@ namespace HybridCLR.Editor.Meta
{ {
public class UnityPluginAssemblyResolver : IAssemblyResolver 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) public string ResolveAssembly(string assemblyName, bool throwExIfNotFind)
{ {
foreach(var dll in Directory.GetFiles(UnityEngine.Application.dataPath, "*.dll", SearchOption.AllDirectories)) foreach(var dll in Directory.GetFiles(UnityEngine.Application.dataPath, "*.dll", SearchOption.AllDirectories))
{ {
if (Path.GetFileNameWithoutExtension(dll) == assemblyName && dll.Contains("Plugins")) if (Path.GetFileNameWithoutExtension(dll) == assemblyName && IsPluginDll(dll))
{ {
Debug.Log($"plugin:{dll}"); Debug.Log($"plugin:{dll}");
return dll; return dll;

View File

@ -85,7 +85,7 @@ namespace HybridCLR.Editor
public static IAssemblyResolver CreateBuildTargetAssemblyResolver(UnityEditor.BuildTarget target) public static IAssemblyResolver CreateBuildTargetAssemblyResolver(UnityEditor.BuildTarget target)
{ {
return new CombinedAssemblyResolver(new PathAssemblyResolver( return new CombinedAssemblyResolver(new PathAssemblyResolver(
SettingsUtil.GetHotFixDllsOutputDirByTarget(target)), SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target)),
new UnityPluginAssemblyResolver(), new UnityPluginAssemblyResolver(),
new UnityEditorAssemblyResolver()); new UnityEditorAssemblyResolver());
} }

View File

@ -28,11 +28,11 @@ namespace HybridCLR.Editor
public static string Dataunity3dBinFile { get; } = "data.unity3d"; public static string Dataunity3dBinFile { get; } = "data.unity3d";
public static string HotFixDllsOutputDir => $"{HybridCLRDataDir}/{GlobalSettings.hotUpdateDllOutputDir}"; public static string HotUpdateDllsRootOutputDir => $"{HybridCLRDataDir}/HotUpdateDlls";
public static string HybridCLRDataDir => $"{ProjectDir}/{GlobalSettings.hybridCLRDataDir}"; public static string HybridCLRDataDir => $"{ProjectDir}/HybridCLRData";
public static string AssembliesPostIl2CppStripDir => $"{HybridCLRDataDir}/{GlobalSettings.strippedAssemblyDir}"; public static string AssembliesPostIl2CppStripDir => $"{HybridCLRDataDir}/AssembliesPostIl2CppStrip";
public static string LocalUnityDataDir => $"{HybridCLRDataDir}/LocalIl2CppData-{Application.platform}"; public static string LocalUnityDataDir => $"{HybridCLRDataDir}/LocalIl2CppData-{Application.platform}";
@ -42,9 +42,9 @@ namespace HybridCLR.Editor
public static string Il2CppBuildCacheDir { get; } = $"{ProjectDir}/Library/Il2cppBuildCache"; public static string Il2CppBuildCacheDir { get; } = $"{ProjectDir}/Library/Il2cppBuildCache";
public static string GetHotFixDllsOutputDirByTarget(BuildTarget target) public static string GetHotUpdateDllsOutputDirByTarget(BuildTarget target)
{ {
return $"{HotFixDllsOutputDir}/{target}"; return $"{HotUpdateDllsRootOutputDir}/{target}";
} }
public static string GetAssembliesPostIl2CppStripDir(BuildTarget target) public static string GetAssembliesPostIl2CppStripDir(BuildTarget target)

View File

@ -18,10 +18,16 @@ namespace HybridCLR
private const string dllName = "il2cpp"; private const string dllName = "il2cpp";
#endif #endif
/// <summary>
/// 加载补充元数据assembly
/// </summary>
/// <param name="dllBytes"></param>
/// <returns></returns>
/// <exception cref="NotSupportedException"></exception>
public static unsafe LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes) public static unsafe LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes)
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
throw new NotSupportedException("LoadMetadataForAOTAssembly can only be invoked in il2cpp"); return LoadImageErrorCode.OK;
#else #else
fixed(byte* data = dllBytes) fixed(byte* data = dllBytes)
{ {
@ -30,18 +36,40 @@ namespace HybridCLR
#endif #endif
} }
/// <summary>
/// 加载补充元数据assembly
/// </summary>
/// <param name="dllBytes"></param>
/// <param name="dllSize"></param>
/// <returns></returns>
[DllImport(dllName, EntryPoint = "RuntimeApi_LoadMetadataForAOTAssembly")] [DllImport(dllName, EntryPoint = "RuntimeApi_LoadMetadataForAOTAssembly")]
public static extern int LoadMetadataForAOTAssembly(IntPtr dllBytes, int dllSize); public static extern int LoadMetadataForAOTAssembly(IntPtr dllBytes, int dllSize);
/// <summary>
/// 获取解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
/// </summary>
/// <returns></returns>
[DllImport(dllName, EntryPoint = "RuntimeApi_GetInterpreterThreadObjectStackSize")] [DllImport(dllName, EntryPoint = "RuntimeApi_GetInterpreterThreadObjectStackSize")]
public static extern int GetInterpreterThreadObjectStackSize(); public static extern int GetInterpreterThreadObjectStackSize();
/// <summary>
/// 设置解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
/// </summary>
/// <param name="size"></param>
[DllImport(dllName, EntryPoint = "RuntimeApi_SetInterpreterThreadObjectStackSize")] [DllImport(dllName, EntryPoint = "RuntimeApi_SetInterpreterThreadObjectStackSize")]
public static extern void SetInterpreterThreadObjectStackSize(int size); public static extern void SetInterpreterThreadObjectStackSize(int size);
/// <summary>
/// 获取解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小)
/// </summary>
/// <returns></returns>
[DllImport(dllName, EntryPoint = "RuntimeApi_GetInterpreterThreadFrameStackSize")] [DllImport(dllName, EntryPoint = "RuntimeApi_GetInterpreterThreadFrameStackSize")]
public static extern int GetInterpreterThreadFrameStackSize(); public static extern int GetInterpreterThreadFrameStackSize();
/// <summary>
/// 设置解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小)
/// </summary>
/// <param name="size"></param>
[DllImport(dllName, EntryPoint = "RuntimeApi_SetInterpreterThreadFrameStackSize")] [DllImport(dllName, EntryPoint = "RuntimeApi_SetInterpreterThreadFrameStackSize")]
public static extern void SetInterpreterThreadFrameStackSize(int size); public static extern void SetInterpreterThreadFrameStackSize(int size);
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "com.focus-creative-games.hybridclr_unity", "name": "com.focus-creative-games.hybridclr_unity",
"version": "0.3.4", "version": "0.3.5",
"displayName": "HybridCLR", "displayName": "HybridCLR",
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
"category": "Runtime", "category": "Runtime",