From 00f94335c3a2640e1ae9b20c678c62ac47eceaa7 Mon Sep 17 00:00:00 2001 From: walon Date: Wed, 14 Dec 2022 14:11:32 +0800 Subject: [PATCH] =?UTF-8?q?[refactor]=20=E9=87=8D=E6=9E=84=E5=B9=B6?= =?UTF-8?q?=E4=B8=94=E4=BF=AE=E5=A4=8D=E4=BA=86Generate=E7=9B=B8=E5=85=B3A?= =?UTF-8?q?ssembly=20Resolve=E6=BD=9C=E5=9C=A8=E7=9A=84bug=E3=80=82=20[opt?= =?UTF-8?q?]=20=E4=BC=98=E5=8C=96=20PrebuildCommand.Build=20=E4=B8=AD?= =?UTF-8?q?=E5=A4=9A=E6=AC=A1=E7=BC=96=E8=AF=91=E7=83=AD=E6=9B=B4=E6=96=B0?= =?UTF-8?q?dll=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=A4=A7=E5=B9=85?= =?UTF-8?q?=E7=BC=A9=E7=9F=AD=E4=BA=86=E6=97=B6=E9=97=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BuildProcessors/FilterHotFixAssemblies.cs | 19 +++---- .../Commands/AOTReferenceGeneratorCommand.cs | 18 +++---- Editor/Commands/Il2CppDefGeneratorCommand.cs | 2 +- Editor/Commands/LinkGeneratorCommand.cs | 14 +++-- .../Commands/MethodBridgeGeneratorCommand.cs | 28 ++++------ Editor/Commands/PrebuildCommand.cs | 16 +++--- .../ReversePInvokeWrapperGeneratorCommand.cs | 16 ++++-- Editor/Link/Analyzer.cs | 13 ++--- Editor/Meta/AssemblyResolverBase.cs | 26 ++++++++++ ...r.cs.meta => AssemblyResolverBase.cs.meta} | 2 +- Editor/Meta/CombinedAssemblyResolver.cs | 14 +++-- Editor/Meta/FixedSetAssemblyResolver.cs | 37 ++++++++++++++ ....meta => FixedSetAssemblyResolver.cs.meta} | 2 +- Editor/Meta/MetaUtil.cs | 51 +++++++------------ Editor/Meta/PathAssemblyResolver.cs | 14 +++-- Editor/Meta/UnityDotNetAOTAssemblyResolver.cs | 43 ---------------- Editor/Meta/UnityEditorAssemblyResolver.cs | 26 ---------- .../Meta/UnityEditorAssemblyResolver.cs.meta | 11 ---- Editor/Meta/UnityPluginAssemblyResolver.cs | 44 ---------------- package.json | 2 +- 20 files changed, 154 insertions(+), 244 deletions(-) create mode 100644 Editor/Meta/AssemblyResolverBase.cs rename Editor/Meta/{UnityPluginAssemblyResolver.cs.meta => AssemblyResolverBase.cs.meta} (83%) create mode 100644 Editor/Meta/FixedSetAssemblyResolver.cs rename Editor/Meta/{UnityDotNetAOTAssemblyResolver.cs.meta => FixedSetAssemblyResolver.cs.meta} (83%) delete mode 100644 Editor/Meta/UnityDotNetAOTAssemblyResolver.cs delete mode 100644 Editor/Meta/UnityEditorAssemblyResolver.cs delete mode 100644 Editor/Meta/UnityEditorAssemblyResolver.cs.meta delete mode 100644 Editor/Meta/UnityPluginAssemblyResolver.cs diff --git a/Editor/BuildProcessors/FilterHotFixAssemblies.cs b/Editor/BuildProcessors/FilterHotFixAssemblies.cs index 2488179..db1184d 100644 --- a/Editor/BuildProcessors/FilterHotFixAssemblies.cs +++ b/Editor/BuildProcessors/FilterHotFixAssemblies.cs @@ -24,11 +24,12 @@ namespace HybridCLR.Editor.BuildProcessors Debug.Log($"[FilterHotFixAssemblies] disabled"); return assemblies; } - List allHotUpdateDllFiles = SettingsUtil.HotUpdateAssemblyFiles; + List allHotUpdateDllNames = SettingsUtil.HotUpdateAssemblyNames; + List allHotupdateDllFiles = SettingsUtil.HotUpdateAssemblyFiles; // 检查是否重复填写 var hotUpdateDllSet = new HashSet(); - foreach(var hotUpdateDll in allHotUpdateDllFiles) + foreach(var hotUpdateDll in allHotUpdateDllNames) { if (!hotUpdateDllSet.Add(hotUpdateDll)) { @@ -36,20 +37,20 @@ namespace HybridCLR.Editor.BuildProcessors } } - var assResolver = MetaUtil.CreateHotUpdateAssemblyResolver(EditorUserBuildSettings.activeBuildTarget); + var assResolver = MetaUtil.CreateHotUpdateAssemblyResolver(EditorUserBuildSettings.activeBuildTarget, allHotUpdateDllNames); // 检查是否填写了正确的dll名称 - foreach (var hotUpdateDll in allHotUpdateDllFiles) + foreach (var hotUpdateDllName in allHotUpdateDllNames) { - string hotUpdateAssName = hotUpdateDll.Substring(0, hotUpdateDll.Length - 4); - if (assemblies.All(ass => !ass.EndsWith(hotUpdateDll)) && string.IsNullOrEmpty(assResolver.ResolveAssembly(hotUpdateAssName, false))) + string hotUpdateDllFile = hotUpdateDllName + ".dll"; + if (assemblies.All(ass => !ass.EndsWith(hotUpdateDllFile)) && string.IsNullOrEmpty(assResolver.ResolveAssembly(hotUpdateDllName, false))) { - throw new Exception($"热更新 assembly:{hotUpdateDll} 不存在,请检查拼写错误"); + throw new Exception($"热更新 assembly:{hotUpdateDllFile} 不存在,请检查拼写错误"); } - Debug.Log($"[FilterHotFixAssemblies] 过滤热更新assembly:{hotUpdateDll}"); + Debug.Log($"[FilterHotFixAssemblies] 过滤热更新assembly:{hotUpdateDllFile}"); } // 将热更dll从打包列表中移除 - return assemblies.Where(ass => allHotUpdateDllFiles.All(dll => !ass.EndsWith(dll, StringComparison.OrdinalIgnoreCase))).ToArray(); + return assemblies.Where(ass => allHotupdateDllFiles.All(dll => !ass.EndsWith(dll, StringComparison.OrdinalIgnoreCase))).ToArray(); } } } diff --git a/Editor/Commands/AOTReferenceGeneratorCommand.cs b/Editor/Commands/AOTReferenceGeneratorCommand.cs index a56d12f..11e10ad 100644 --- a/Editor/Commands/AOTReferenceGeneratorCommand.cs +++ b/Editor/Commands/AOTReferenceGeneratorCommand.cs @@ -14,23 +14,19 @@ namespace HybridCLR.Editor.Commands { [MenuItem("HybridCLR/Generate/AOTGenericReference", priority = 102)] - public static void GenerateAOTGenericReference() + public static void CompileAndGenerateAOTGenericReference() { - GenerateAOTGenericReference(true); + BuildTarget target = EditorUserBuildSettings.activeBuildTarget; + CompileDllCommand.CompileDll(target); + GenerateAOTGenericReference(target); } - public static void GenerateAOTGenericReference(bool compileDll) + public static void GenerateAOTGenericReference(BuildTarget target) { - // 此处理论会有点问题,打每个平台的时候,都得针对当前平台生成桥接函数 - // 但影响不大,先这样吧 - if (compileDll) - { - CompileDllCommand.CompileDllActiveBuildTarget(); - } - var gs = SettingsUtil.HybridCLRSettings; + List hotUpdateDllNames = SettingsUtil.HotUpdateAssemblyNames; - using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), SettingsUtil.HotUpdateAssemblyNames)) + using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDllNames), hotUpdateDllNames)) { var analyzer = new Analyzer(new Analyzer.Options { diff --git a/Editor/Commands/Il2CppDefGeneratorCommand.cs b/Editor/Commands/Il2CppDefGeneratorCommand.cs index b503aa1..6a9e175 100644 --- a/Editor/Commands/Il2CppDefGeneratorCommand.cs +++ b/Editor/Commands/Il2CppDefGeneratorCommand.cs @@ -17,7 +17,7 @@ namespace HybridCLR.Editor.Commands { var options = new Il2CppDef.Il2CppDefGenerator.Options() { - UnityVersion = UnityEngine.Application.unityVersion, + UnityVersion = Application.unityVersion, OutputFile = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/il2cpp-config.h", }; diff --git a/Editor/Commands/LinkGeneratorCommand.cs b/Editor/Commands/LinkGeneratorCommand.cs index 4d6a16f..68217ea 100644 --- a/Editor/Commands/LinkGeneratorCommand.cs +++ b/Editor/Commands/LinkGeneratorCommand.cs @@ -1,4 +1,5 @@ using HybridCLR.Editor.Link; +using HybridCLR.Editor.Meta; using System; using System.Collections.Generic; using System.Reflection; @@ -14,21 +15,18 @@ namespace HybridCLR.Editor.Commands [MenuItem("HybridCLR/Generate/LinkXml", priority = 100)] public static void GenerateLinkXml() { - GenerateLinkXml(true); + BuildTarget target = EditorUserBuildSettings.activeBuildTarget; + CompileDllCommand.CompileDll(target); + GenerateLinkXml(target); } - public static void GenerateLinkXml(bool compileDll) + public static void GenerateLinkXml(BuildTarget target) { - if (compileDll) - { - CompileDllCommand.CompileDllActiveBuildTarget(); - } - var ls = SettingsUtil.HybridCLRSettings; List hotfixAssemblies = SettingsUtil.HotUpdateAssemblyNames; - var analyzer = new Analyzer(Meta.MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), HybridCLRSettings.Instance.collectAssetReferenceTypes); + var analyzer = new Analyzer(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotfixAssemblies), HybridCLRSettings.Instance.collectAssetReferenceTypes); var refTypes = analyzer.CollectRefs(hotfixAssemblies); Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssemblies.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}"); diff --git a/Editor/Commands/MethodBridgeGeneratorCommand.cs b/Editor/Commands/MethodBridgeGeneratorCommand.cs index 6fb3270..e0c7447 100644 --- a/Editor/Commands/MethodBridgeGeneratorCommand.cs +++ b/Editor/Commands/MethodBridgeGeneratorCommand.cs @@ -45,27 +45,17 @@ namespace HybridCLR.Editor.Commands } [MenuItem("HybridCLR/Generate/MethodBridge", priority = 101)] - public static void GenerateMethodBridge() - { - GenerateMethodBridge(true); - } - - static IAssemblyResolver CreateBuildTargetAssemblyResolver(BuildTarget target) - { - return new CombinedAssemblyResolver( - new PathAssemblyResolver(SettingsUtil.GetAssembliesPostIl2CppStripDir(target)), - MetaUtil.CreateHotUpdateAssemblyResolver(target) - ); - } - - public static void GenerateMethodBridge(bool compileDll) + public static void CompileAndGenerateMethodBridge() { BuildTarget target = EditorUserBuildSettings.activeBuildTarget; - if (compileDll) - { - CompileDllCommand.CompileDllActiveBuildTarget(); - } - using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(CreateBuildTargetAssemblyResolver(target), SettingsUtil.HotUpdateAssemblyNames)) + CompileDllCommand.CompileDll(target); + GenerateMethodBridge(target); + } + + public static void GenerateMethodBridge(BuildTarget target) + { + List hotUpdateDllNames = SettingsUtil.HotUpdateAssemblyNames; + using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDllNames), hotUpdateDllNames)) { var analyzer = new Analyzer(new Analyzer.Options { diff --git a/Editor/Commands/PrebuildCommand.cs b/Editor/Commands/PrebuildCommand.cs index d2a64d5..30bf910 100644 --- a/Editor/Commands/PrebuildCommand.cs +++ b/Editor/Commands/PrebuildCommand.cs @@ -15,16 +15,18 @@ namespace HybridCLR.Editor.Commands [MenuItem("HybridCLR/Generate/All", priority = 200)] public static void GenerateAll() { + BuildTarget target = EditorUserBuildSettings.activeBuildTarget; + CompileDllCommand.CompileDll(target); + Il2CppDefGeneratorCommand.GenerateIl2CppDef(); - // 顺序随意 - ReversePInvokeWrapperGeneratorCommand.GenerateReversePInvokeWrapper(); - // AOTReferenceGeneratorCommand 涉及到代码生成,必须在MethodBridgeGeneratorCommand之前 - AOTReferenceGeneratorCommand.GenerateAOTGenericReference(); - MethodBridgeGeneratorCommand.GenerateMethodBridge(); + // 这几个生成依赖HotUpdateDlls + LinkGeneratorCommand.GenerateLinkXml(target); + ReversePInvokeWrapperGeneratorCommand.GenerateReversePInvokeWrapper(target); + AOTReferenceGeneratorCommand.GenerateAOTGenericReference(target); - // 顺序随意,只要保证 GenerateLinkXml之前有调用过CompileDll即可 - LinkGeneratorCommand.GenerateLinkXml(false); + // 桥接函数生成依赖于AOT dll,必须保证已经build过,生成AOT dll + MethodBridgeGeneratorCommand.GenerateMethodBridge(target); } } } diff --git a/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs b/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs index 706c019..4f097ef 100644 --- a/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs +++ b/Editor/Commands/ReversePInvokeWrapperGeneratorCommand.cs @@ -19,12 +19,20 @@ namespace HybridCLR.Editor.Commands { [MenuItem("HybridCLR/Generate/ReversePInvokeWrapper", priority = 103)] - public static void GenerateReversePInvokeWrapper() + + public static void CompileAndGenerateReversePInvokeWrapper() { - CompileDllCommand.CompileDllActiveBuildTarget(); - using (var cache = new AssemblyCache(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget))) + BuildTarget target = EditorUserBuildSettings.activeBuildTarget; + CompileDllCommand.CompileDll(target); + GenerateReversePInvokeWrapper(target); + } + + public static void GenerateReversePInvokeWrapper(BuildTarget target) + { + List hotUpdateDlls = SettingsUtil.HotUpdateAssemblyNames; + using (var cache = new AssemblyCache(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDlls))) { - var analyzer = new ReversePInvokeWrap.Analyzer(cache, SettingsUtil.HotUpdateAssemblyNames); + var analyzer = new ReversePInvokeWrap.Analyzer(cache, hotUpdateDlls); analyzer.Run(); diff --git a/Editor/Link/Analyzer.cs b/Editor/Link/Analyzer.cs index 71b1cbf..cb1ea70 100644 --- a/Editor/Link/Analyzer.cs +++ b/Editor/Link/Analyzer.cs @@ -26,14 +26,7 @@ namespace HybridCLR.Editor.Link { using (var assCollector = new AssemblyCache(_resolver)) { - var rootAssemblyName = new HashSet(); - foreach (var ass in rootAssemblies) - { - if (!rootAssemblyName.Add(ass)) - { - throw new Exception($"assembly:{ass} 重复"); - } - } + var rootAssemblyNames = new HashSet(rootAssemblies); var typeRefs = new HashSet(TypeEqualityComparer.Instance); foreach (var rootAss in rootAssemblies) @@ -41,7 +34,7 @@ namespace HybridCLR.Editor.Link var dnAss = assCollector.LoadModule(rootAss, _analyzeAssetType); foreach (var type in dnAss.GetTypeRefs()) { - if (!rootAssemblyName.Contains(type.DefinitionAssembly.Name.ToString())) + if (!rootAssemblyNames.Contains(type.DefinitionAssembly.Name.ToString())) { typeRefs.Add(type); } @@ -51,7 +44,7 @@ namespace HybridCLR.Editor.Link if (_analyzeAssetType) { var modsExludeRoots = assCollector.LoadedModules - .Where(e => !rootAssemblyName.Contains(e.Key)) + .Where(e => !rootAssemblyNames.Contains(e.Key)) .ToDictionary(e => e.Key, e => e.Value); CollectObjectTypeInAssets(modsExludeRoots, typeRefs); } diff --git a/Editor/Meta/AssemblyResolverBase.cs b/Editor/Meta/AssemblyResolverBase.cs new file mode 100644 index 0000000..c8fc03f --- /dev/null +++ b/Editor/Meta/AssemblyResolverBase.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HybridCLR.Editor.Meta +{ + public abstract class AssemblyResolverBase : IAssemblyResolver + { + public string ResolveAssembly(string assemblyName, bool throwExIfNotFind) + { + if (TryResolveAssembly(assemblyName, out string assemblyPath)) + { + return assemblyPath; + } + if (throwExIfNotFind) + { + throw new Exception($"resolve assembly:{assemblyName} 失败! 如果是热更新dll找不到,请先运行`HybridCLR/CompileDll/ActiveBuildTarget`编译生成热更新dll。如果是AOT dll找不到,请先运行`HybridCLR/Generate/LinkXml`,接着在`Build Settings`中打包或者导出工程来生成AOT dll"); + } + return null; + } + + protected abstract bool TryResolveAssembly(string assemblyName, out string assemblyPath); + } +} diff --git a/Editor/Meta/UnityPluginAssemblyResolver.cs.meta b/Editor/Meta/AssemblyResolverBase.cs.meta similarity index 83% rename from Editor/Meta/UnityPluginAssemblyResolver.cs.meta rename to Editor/Meta/AssemblyResolverBase.cs.meta index 707e174..e153d4e 100644 --- a/Editor/Meta/UnityPluginAssemblyResolver.cs.meta +++ b/Editor/Meta/AssemblyResolverBase.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6c235be11c219a74fa5eb55ed54e7662 +guid: 5f8d48774b790364cbd36f1f68fd6614 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/Meta/CombinedAssemblyResolver.cs b/Editor/Meta/CombinedAssemblyResolver.cs index c8f663a..31a0c51 100644 --- a/Editor/Meta/CombinedAssemblyResolver.cs +++ b/Editor/Meta/CombinedAssemblyResolver.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace HybridCLR.Editor.Meta { - public class CombinedAssemblyResolver : IAssemblyResolver + public class CombinedAssemblyResolver : AssemblyResolverBase { private readonly IAssemblyResolver[] _resolvers; @@ -15,21 +15,19 @@ namespace HybridCLR.Editor.Meta _resolvers = resolvers; } - public string ResolveAssembly(string assemblyName, bool throwExIfNotFind) + protected override bool TryResolveAssembly(string assemblyName, out string assemblyPath) { foreach(var resolver in _resolvers) { var assembly = resolver.ResolveAssembly(assemblyName, false); if (assembly != null) { - return assembly; + assemblyPath = assembly; + return true; } } - if (throwExIfNotFind) - { - throw new Exception($"resolve assembly:{assemblyName} fail"); - } - return null; + assemblyPath = null; + return false; } } } diff --git a/Editor/Meta/FixedSetAssemblyResolver.cs b/Editor/Meta/FixedSetAssemblyResolver.cs new file mode 100644 index 0000000..5bee4e4 --- /dev/null +++ b/Editor/Meta/FixedSetAssemblyResolver.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace HybridCLR.Editor.Meta +{ + public class FixedSetAssemblyResolver : AssemblyResolverBase + { + private readonly string _rootDir; + private readonly HashSet _fileNames; + + public FixedSetAssemblyResolver(string rootDir, IEnumerable fileNameNotExts) + { + _rootDir = rootDir; + _fileNames = new HashSet(fileNameNotExts); + } + + protected override bool TryResolveAssembly(string assemblyName, out string assemblyPath) + { + if (_fileNames.Contains(assemblyName)) + { + assemblyPath = $"{_rootDir}/{assemblyName}.dll"; + if (File.Exists(assemblyPath)) + { + Debug.Log($"[FixedSetAssemblyResolver] resolve:{assemblyName} path:{assemblyPath}"); + return true; + } + } + assemblyPath = null; + return false; + } + } +} diff --git a/Editor/Meta/UnityDotNetAOTAssemblyResolver.cs.meta b/Editor/Meta/FixedSetAssemblyResolver.cs.meta similarity index 83% rename from Editor/Meta/UnityDotNetAOTAssemblyResolver.cs.meta rename to Editor/Meta/FixedSetAssemblyResolver.cs.meta index ce41f39..cc4fb61 100644 --- a/Editor/Meta/UnityDotNetAOTAssemblyResolver.cs.meta +++ b/Editor/Meta/FixedSetAssemblyResolver.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 87ece9687eaa17648bdc9d2c9bf30520 +guid: f135accd10f42c64b9735c3aa8cb1e77 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/Meta/MetaUtil.cs b/Editor/Meta/MetaUtil.cs index b325563..539eb91 100644 --- a/Editor/Meta/MetaUtil.cs +++ b/Editor/Meta/MetaUtil.cs @@ -120,52 +120,39 @@ namespace HybridCLR.Editor.Meta return typeSigs.Select(s => ToShareTypeSig(s)).ToList(); } - public static IAssemblyResolver CreateHotUpdateAssemblyResolver(BuildTarget target) + public static IAssemblyResolver CreateHotUpdateAssemblyResolver(BuildTarget target, List hotUpdateDlls) { var externalDirs = HybridCLRSettings.Instance.externalHotUpdateAssembliyDirs; var defaultHotUpdateOutputDir = SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target); + IAssemblyResolver defaultHotUpdateResolver = new FixedSetAssemblyResolver(defaultHotUpdateOutputDir, hotUpdateDlls); if (externalDirs == null || externalDirs.Length == 0) { - return new PathAssemblyResolver(defaultHotUpdateOutputDir); + return defaultHotUpdateResolver; } else { - var externalDirList = new List(); + var resolvers = new List(); foreach (var dir in externalDirs) { - externalDirList.Add($"{dir}/{target}"); - externalDirList.Add(dir); + resolvers.Add(new FixedSetAssemblyResolver($"{dir}/{target}", hotUpdateDlls)); + resolvers.Add(new FixedSetAssemblyResolver(dir, hotUpdateDlls)); } - externalDirList.Add(defaultHotUpdateOutputDir); - return new PathAssemblyResolver(externalDirList.ToArray()); + resolvers.Add(defaultHotUpdateResolver); + return new CombinedAssemblyResolver(resolvers.ToArray()); } } - public static IAssemblyResolver CreateExternalAssemblyResolver(BuildTarget target) - { - var externalDirs = HybridCLRSettings.Instance.externalHotUpdateAssembliyDirs; - if (externalDirs == null || externalDirs.Length == 0) - { - return new PathAssemblyResolver(); - } - else - { - var externalDirList = new List(); - foreach (var dir in externalDirs) - { - externalDirList.Add($"{dir}/{target}"); - externalDirList.Add(dir); - } - return new PathAssemblyResolver(externalDirList.ToArray()); - } - } - - public static IAssemblyResolver CreateBuildTargetAssemblyResolver(BuildTarget target) + public static IAssemblyResolver CreateAOTAssemblyResolver(BuildTarget target) { - return new CombinedAssemblyResolver(CreateHotUpdateAssemblyResolver(target), - new UnityPluginAssemblyResolver(), - new UnityDotNetAOTAssemblyResolver(), - new UnityEditorAssemblyResolver()); - } + return new PathAssemblyResolver(SettingsUtil.GetAssembliesPostIl2CppStripDir(target)); + } + + public static IAssemblyResolver CreateHotUpdateAndAOTAssemblyResolver(BuildTarget target, List hotUpdateDlls) + { + return new CombinedAssemblyResolver( + CreateHotUpdateAssemblyResolver(target, hotUpdateDlls), + CreateAOTAssemblyResolver(target) + ); + } } } diff --git a/Editor/Meta/PathAssemblyResolver.cs b/Editor/Meta/PathAssemblyResolver.cs index d36aefd..a356117 100644 --- a/Editor/Meta/PathAssemblyResolver.cs +++ b/Editor/Meta/PathAssemblyResolver.cs @@ -8,7 +8,7 @@ using UnityEngine; namespace HybridCLR.Editor.Meta { - public class PathAssemblyResolver : IAssemblyResolver + public class PathAssemblyResolver : AssemblyResolverBase { private readonly string[] _searchPaths; public PathAssemblyResolver(params string[] searchPaths) @@ -16,7 +16,7 @@ namespace HybridCLR.Editor.Meta _searchPaths = searchPaths; } - public string ResolveAssembly(string assemblyName, bool throwExIfNotFind) + protected override bool TryResolveAssembly(string assemblyName, out string assemblyPath) { foreach(var path in _searchPaths) { @@ -24,14 +24,12 @@ namespace HybridCLR.Editor.Meta if (File.Exists(assPath)) { Debug.Log($"resolve {assemblyName} at {assPath}"); - return assPath; + assemblyPath = assPath; + return true; } } - if (throwExIfNotFind) - { - throw new Exception($"resolve assembly:{assemblyName} fail"); - } - return null; + assemblyPath = null; + return false; } } } diff --git a/Editor/Meta/UnityDotNetAOTAssemblyResolver.cs b/Editor/Meta/UnityDotNetAOTAssemblyResolver.cs deleted file mode 100644 index b8df2a6..0000000 --- a/Editor/Meta/UnityDotNetAOTAssemblyResolver.cs +++ /dev/null @@ -1,43 +0,0 @@ -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 UnityDotNetAOTAssemblyResolver : IAssemblyResolver - { - public string ResolveAssembly(string assemblyName, bool throwExIfNotFind) - { - // -#if !UNITY_2021_1_OR_NEWER - var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot/{assemblyName}.dll"; -#else -#if UNITY_STANDALONE_WIN - var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot-win32/{assemblyName}.dll"; -#elif UNITY_STANDALONE_OSX || UNITY_IOS - var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot-macos/{assemblyName}.dll"; -#elif UNITY_STANDALONE_LINUX || UNITY_ANDROID - var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot-linux/{assemblyName}.dll"; -#else - var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot-linux/{assemblyName}.dll"; -#endif -#endif - - if (File.Exists(assemblyFile)) - { - Debug.Log($"UnityAOTAssemblyResolver.ResolveAssembly:{assemblyFile}"); - return assemblyFile; - } - if (throwExIfNotFind) - { - throw new Exception($"resolve assembly:{assemblyName} fail"); - } - return null; - } - } -} diff --git a/Editor/Meta/UnityEditorAssemblyResolver.cs b/Editor/Meta/UnityEditorAssemblyResolver.cs deleted file mode 100644 index 7057249..0000000 --- a/Editor/Meta/UnityEditorAssemblyResolver.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace HybridCLR.Editor.Meta -{ - public class UnityEditorAssemblyResolver : IAssemblyResolver - { - public string ResolveAssembly(string assemblyName, bool throwExIfNotFind) - { - var refAss = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == assemblyName); - if (refAss != null) - { - return refAss.Location; - } - if (throwExIfNotFind) - { - throw new Exception($"resolve assembly:{assemblyName} fail"); - } - return null; - } - } -} diff --git a/Editor/Meta/UnityEditorAssemblyResolver.cs.meta b/Editor/Meta/UnityEditorAssemblyResolver.cs.meta deleted file mode 100644 index fc640e4..0000000 --- a/Editor/Meta/UnityEditorAssemblyResolver.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 78d06a3ad750c0b4b80b583188b02df3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/Meta/UnityPluginAssemblyResolver.cs b/Editor/Meta/UnityPluginAssemblyResolver.cs deleted file mode 100644 index b7ac13a..0000000 --- a/Editor/Meta/UnityPluginAssemblyResolver.cs +++ /dev/null @@ -1,44 +0,0 @@ -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 - { - private static readonly HashSet s_ignoreDirs = new HashSet - { - "Editor", - "StreamingAssets", - "Resources", - }; - - private bool IsPluginDll(string dllPath) - { - var fileOrDirs = new HashSet(dllPath.Split('\\', '/')); - return !fileOrDirs.Any(dir => dir.EndsWith("~")) && !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 && IsPluginDll(dll)) - { - Debug.Log($"UnityPluginAssemblyResolver.ResolveAssembly:{dll}"); - return dll; - } - } - if (throwExIfNotFind) - { - throw new Exception($"resolve assembly:{assemblyName} fail"); - } - return null; - } - } -} diff --git a/package.json b/package.json index 2ad77f6..448191d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.focus-creative-games.hybridclr_unity", - "version": "1.1.13", + "version": "1.1.14", "displayName": "HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "category": "Runtime",