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",