diff --git a/Editor/Commands/MethodBridgeGeneratorCommand.cs b/Editor/Commands/MethodBridgeGeneratorCommand.cs index 08879d9..de83cb7 100644 --- a/Editor/Commands/MethodBridgeGeneratorCommand.cs +++ b/Editor/Commands/MethodBridgeGeneratorCommand.cs @@ -10,6 +10,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using UnityEditor; +using UnityEditor.Build; using UnityEngine; namespace HybridCLR.Editor.Commands @@ -47,14 +48,20 @@ namespace HybridCLR.Editor.Commands public static void CompileAndGenerateMethodBridge() { BuildTarget target = EditorUserBuildSettings.activeBuildTarget; - CompileDllCommand.CompileDll(target); GenerateMethodBridge(target); } public static void GenerateMethodBridge(BuildTarget target) { - List hotUpdateDllNames = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved; - using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDllNames), hotUpdateDllNames)) + string aotDllDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target); + List aotAssemblyNames = Directory.Exists(aotDllDir) ? + Directory.GetFiles(aotDllDir, "*.dll", SearchOption.TopDirectoryOnly).Select(Path.GetFileNameWithoutExtension).ToList() + : new List(); + if (aotAssemblyNames.Count == 0) + { + throw new Exception($"no aot assembly found. please run `HybridCLR/Generate/All` or `HybridCLR/Generate/AotDlls` to generate aot dlls before runing `HybridCLR/Generate/MethodBridge`"); + } + using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateAOTAssemblyResolver(target), aotAssemblyNames)) { var analyzer = new Analyzer(new Analyzer.Options { diff --git a/Editor/Meta/AssemblyReferenceDeepCollector.cs b/Editor/Meta/AssemblyReferenceDeepCollector.cs index 39f0f61..8850aac 100644 --- a/Editor/Meta/AssemblyReferenceDeepCollector.cs +++ b/Editor/Meta/AssemblyReferenceDeepCollector.cs @@ -30,6 +30,11 @@ namespace HybridCLR.Editor.Meta return LoadedModules.Where(e => !_rootAssemblies.Contains(e.Key)).Select(e => e.Value).ToList(); } + public List GetLoadedModules() + { + return LoadedModules.Select(e => e.Value).ToList(); + } + public List GetLoadedModulesOfRootAssemblies() { return _rootAssemblies.Select(ass => LoadedModules[ass]).ToList(); diff --git a/Editor/MethodBridge/Analyzer.cs b/Editor/MethodBridge/Analyzer.cs index 520d5ae..59e2dd7 100644 --- a/Editor/MethodBridge/Analyzer.cs +++ b/Editor/MethodBridge/Analyzer.cs @@ -143,7 +143,7 @@ namespace HybridCLR.Editor.MethodBridge { // 将所有非泛型函数全部加入函数列表,同时立马walk这些method。 // 后续迭代中将只遍历MethodSpec - foreach (var ass in _assemblyCollector.GetLoadedModulesExcludeRootAssemblies()) + foreach (var ass in _assemblyCollector.GetLoadedModules()) { foreach (TypeDef typeDef in ass.GetTypes()) {