From f2ee5e7af1a4f77f4b3ddfc0b6cedd0c38520dca Mon Sep 17 00:00:00 2001 From: walon Date: Sat, 8 Oct 2022 12:35:34 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8D=20UnityPluginAssembl?= =?UTF-8?q?yResolver=20=E6=90=9C=E7=B4=A2=E4=BE=9D=E8=B5=96dll=E6=9C=AA?= =?UTF-8?q?=E6=A3=80=E6=9F=A5Plugins=E5=A4=96=E7=9B=AE=E5=BD=95=E7=9A=84bu?= =?UTF-8?q?g=20[refactor]=20=E4=B8=80=E4=BA=9B=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=20hotfix=20->=20hotUpdate=20[refactor]=20HybridCLRGlobalSettin?= =?UTF-8?q?gs=E7=A7=BB=E9=99=A4=20hotUpdateDllOutputDir=E3=80=81=20hybridC?= =?UTF-8?q?LRDataDir=E3=80=81strippedAssemblyDir=E8=BF=99=E4=B8=89?= =?UTF-8?q?=E4=B8=AA=E9=85=8D=E7=BD=AE=E9=A1=B9=EF=BC=8C=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E5=86=99=E6=AD=BB=20[change]=20Editor?= =?UTF-8?q?=E4=B8=8B=E8=B0=83=E7=94=A8LoadMetadataForAOTAssembly=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=88=90=E5=8A=9F=E8=80=8C=E4=B8=8D=E6=98=AF=E6=8A=9B?= =?UTF-8?q?=E5=87=BA=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/Commands/CompileDllCommand.cs | 2 +- Editor/HybridCLRGlobalSettings.cs | 9 ------- Editor/Installer/InstallerWindow.cs | 6 ++--- Editor/Meta/UnityPluginAssemblyResolver.cs | 15 ++++++++++- Editor/MetaUtil.cs | 2 +- Editor/SettingsUtil.cs | 10 ++++---- Runtime/RuntimeApi.cs | 30 +++++++++++++++++++++- package.json | 2 +- 8 files changed, 54 insertions(+), 22 deletions(-) diff --git a/Editor/Commands/CompileDllCommand.cs b/Editor/Commands/CompileDllCommand.cs index 4bc95c8..1c76c7d 100644 --- a/Editor/Commands/CompileDllCommand.cs +++ b/Editor/Commands/CompileDllCommand.cs @@ -30,7 +30,7 @@ namespace HybridCLR.Editor.Commands public static void CompileDll(BuildTarget target) { - CompileDll(SettingsUtil.GetHotFixDllsOutputDirByTarget(target), target); + CompileDll(SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target), target); } [MenuItem("HybridCLR/CompileDll/ActiveBuildTarget", priority = 100)] diff --git a/Editor/HybridCLRGlobalSettings.cs b/Editor/HybridCLRGlobalSettings.cs index 675e02c..6b4c145 100644 --- a/Editor/HybridCLRGlobalSettings.cs +++ b/Editor/HybridCLRGlobalSettings.cs @@ -33,13 +33,4 @@ public class HybridCLRGlobalSettings : ScriptableObject [Header("MethodBridge泛型搜索迭代次数")] public int maxMethodBridgeGenericIteration = 4; - - [Header("热更新dll输出目录(相对HybridCLRData目录)")] - public string hotUpdateDllOutputDir = "HotUpdateDlls"; - - [Header("HybridCLRData目录(相对工程目录)")] - public string hybridCLRDataDir = "HybridCLRData"; - - [Header("裁剪后的AOT assembly输出目录")] - public string strippedAssemblyDir = "AssembliesPostIl2CppStrip"; } diff --git a/Editor/Installer/InstallerWindow.cs b/Editor/Installer/InstallerWindow.cs index 07ff58b..0383d1c 100644 --- a/Editor/Installer/InstallerWindow.cs +++ b/Editor/Installer/InstallerWindow.cs @@ -29,8 +29,8 @@ namespace HybridCLR.Editor.Installer $"你所在项目的Unity版本可以与il2cpp_plus版本:{m_Controller.Il2CppBranch} 不一样。\n" + $"如果你的Unity的版本号 >= {minCompatibleVersion}, 可以直接安装。\n" + $"如果你的Unity的版本号 < {minCompatibleVersion}, \n" - + $"由于安装HybridCLR时需要从il2cpp_plus对应版本{m_Controller.Il2CppBranch}(而不是你项目版本)拷贝il2cpp目录,\n" - + $"你必须同时安装相应版本 {m_Controller.Il2CppBranch} 才能完成安装", EditorStyles.wordWrappedLabel); + + $"由于安装HybridCLR时需要从il2cpp_plus兼容版本{m_Controller.Il2CppBranch}(而不是你项目版本)拷贝il2cpp目录,\n" + + $"你必须同时安装兼容版本 {m_Controller.Il2CppBranch} 才能完成安装", EditorStyles.wordWrappedLabel); EditorGUILayout.LabelField("=============================================="); GUILayout.Space(10f); @@ -38,7 +38,7 @@ namespace HybridCLR.Editor.Installer EditorGUILayout.LabelField($"安装状态:{(m_Controller.HasInstalledHybridCLR() ? "已安装" : "未安装")}", EditorStyles.boldLabel); GUILayout.Space(5f); 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); GUIInstallButton("安装最新HybridCLR插件代码到本项目", "安装", InitHybridCLR); EditorGUILayout.EndVertical(); diff --git a/Editor/Meta/UnityPluginAssemblyResolver.cs b/Editor/Meta/UnityPluginAssemblyResolver.cs index 4119722..2e747c7 100644 --- a/Editor/Meta/UnityPluginAssemblyResolver.cs +++ b/Editor/Meta/UnityPluginAssemblyResolver.cs @@ -11,11 +11,24 @@ namespace HybridCLR.Editor.Meta { public class UnityPluginAssemblyResolver : IAssemblyResolver { + private static readonly HashSet s_ignoreDirs = new HashSet + { + "Editor", + "StreamingAssets", + "Resources", + }; + + private bool IsPluginDll(string dllPath) + { + var fileOrDirs = new HashSet(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 && dll.Contains("Plugins")) + if (Path.GetFileNameWithoutExtension(dll) == assemblyName && IsPluginDll(dll)) { Debug.Log($"plugin:{dll}"); return dll; diff --git a/Editor/MetaUtil.cs b/Editor/MetaUtil.cs index e5f55ca..24fd7fa 100644 --- a/Editor/MetaUtil.cs +++ b/Editor/MetaUtil.cs @@ -85,7 +85,7 @@ namespace HybridCLR.Editor public static IAssemblyResolver CreateBuildTargetAssemblyResolver(UnityEditor.BuildTarget target) { return new CombinedAssemblyResolver(new PathAssemblyResolver( - SettingsUtil.GetHotFixDllsOutputDirByTarget(target)), + SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target)), new UnityPluginAssemblyResolver(), new UnityEditorAssemblyResolver()); } diff --git a/Editor/SettingsUtil.cs b/Editor/SettingsUtil.cs index 1a526cf..cda0a48 100644 --- a/Editor/SettingsUtil.cs +++ b/Editor/SettingsUtil.cs @@ -28,11 +28,11 @@ namespace HybridCLR.Editor 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}"; @@ -42,9 +42,9 @@ namespace HybridCLR.Editor 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) diff --git a/Runtime/RuntimeApi.cs b/Runtime/RuntimeApi.cs index 84552c8..2c0bc0b 100644 --- a/Runtime/RuntimeApi.cs +++ b/Runtime/RuntimeApi.cs @@ -18,10 +18,16 @@ namespace HybridCLR private const string dllName = "il2cpp"; #endif + /// + /// 加载补充元数据assembly + /// + /// + /// + /// public static unsafe LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes) { #if UNITY_EDITOR - throw new NotSupportedException("LoadMetadataForAOTAssembly can only be invoked in il2cpp"); + return LoadImageErrorCode.OK; #else fixed(byte* data = dllBytes) { @@ -30,18 +36,40 @@ namespace HybridCLR #endif } + /// + /// 加载补充元数据assembly + /// + /// + /// + /// [DllImport(dllName, EntryPoint = "RuntimeApi_LoadMetadataForAOTAssembly")] public static extern int LoadMetadataForAOTAssembly(IntPtr dllBytes, int dllSize); + /// + /// 获取解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小) + /// + /// [DllImport(dllName, EntryPoint = "RuntimeApi_GetInterpreterThreadObjectStackSize")] public static extern int GetInterpreterThreadObjectStackSize(); + /// + /// 设置解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小) + /// + /// [DllImport(dllName, EntryPoint = "RuntimeApi_SetInterpreterThreadObjectStackSize")] public static extern void SetInterpreterThreadObjectStackSize(int size); + /// + /// 获取解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小) + /// + /// [DllImport(dllName, EntryPoint = "RuntimeApi_GetInterpreterThreadFrameStackSize")] public static extern int GetInterpreterThreadFrameStackSize(); + /// + /// 设置解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小) + /// + /// [DllImport(dllName, EntryPoint = "RuntimeApi_SetInterpreterThreadFrameStackSize")] public static extern void SetInterpreterThreadFrameStackSize(int size); } diff --git a/package.json b/package.json index a94c781..ec24ed2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.focus-creative-games.hybridclr_unity", - "version": "0.3.4", + "version": "0.3.5", "displayName": "HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "category": "Runtime",