From e3095ccc0165caf7c1f9e028096cf8b219cc1618 Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 14 Oct 2022 14:47:27 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8D=E6=A1=A5=E6=8E=A5?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E9=81=8D=E5=8E=86=E6=94=B6=E9=9B=86=E7=AD=BE?= =?UTF-8?q?=E5=90=8D=E6=97=B6=EF=BC=8C=E6=9C=AA=E7=AD=89=E9=81=8D=E5=8E=86?= =?UTF-8?q?=E5=AE=8C=E5=B0=B1=E7=BB=93=E6=9D=9F=E6=89=A7=E8=A1=8C,?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=94=9F=E6=88=90=E7=9A=84=E6=A1=A5=E6=8E=A5?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8D=E5=AE=8C=E6=95=B4=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/Meta/GenericArgumentContext.cs | 3 +- Editor/Meta/GenericMethod.cs | 5 ++++ Editor/Meta/UnityAOTAssemblyResolver.cs | 30 ++++++++++++++++++++ Editor/Meta/UnityAOTAssemblyResolver.cs.meta | 11 +++++++ Editor/Meta/UnityPluginAssemblyResolver.cs | 2 +- Editor/MetaUtil.cs | 3 +- Editor/MethodBridge/Analyzer.cs | 6 ++-- package.json | 2 +- 8 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 Editor/Meta/UnityAOTAssemblyResolver.cs create mode 100644 Editor/Meta/UnityAOTAssemblyResolver.cs.meta diff --git a/Editor/Meta/GenericArgumentContext.cs b/Editor/Meta/GenericArgumentContext.cs index 577fc97..47883f5 100644 --- a/Editor/Meta/GenericArgumentContext.cs +++ b/Editor/Meta/GenericArgumentContext.cs @@ -37,6 +37,7 @@ namespace HybridCLR.Editor.Meta { return typeSig; } + typeSig = typeSig.RemovePinnedAndModifiers(); switch (typeSig.ElementType) { case ElementType.Ptr: return new PtrSig(Resolve(typeSig.Next)); @@ -64,7 +65,7 @@ namespace HybridCLR.Editor.Meta { GenericMVar genericVar = (GenericMVar)typeSig; var newSig = Resolve(methodArgsStack, genericVar.Number, true); - if (newSig is null) + if (newSig == null) { throw new Exception(); } diff --git a/Editor/Meta/GenericMethod.cs b/Editor/Meta/GenericMethod.cs index a725db7..c3cb419 100644 --- a/Editor/Meta/GenericMethod.cs +++ b/Editor/Meta/GenericMethod.cs @@ -42,6 +42,11 @@ namespace HybridCLR.Editor.Meta return _hashCode; } + public override string ToString() + { + return $"{Method}|{string.Join(",", (IEnumerable)KlassInst ?? Array.Empty())}|{string.Join(",", (IEnumerable)MethodInst ?? Array.Empty())}"; + } + private int ComputHashCode() { int hash = MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(Method); diff --git a/Editor/Meta/UnityAOTAssemblyResolver.cs b/Editor/Meta/UnityAOTAssemblyResolver.cs new file mode 100644 index 0000000..fcd0319 --- /dev/null +++ b/Editor/Meta/UnityAOTAssemblyResolver.cs @@ -0,0 +1,30 @@ +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 UnityAOTAssemblyResolver : IAssemblyResolver + { + public string ResolveAssembly(string assemblyName, bool throwExIfNotFind) + { + // + var assemblyFile = $"{UnityEditor.EditorApplication.applicationContentsPath}/MonoBleedingEdge/lib/mono/unityaot/{assemblyName}.dll"; + 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/UnityAOTAssemblyResolver.cs.meta b/Editor/Meta/UnityAOTAssemblyResolver.cs.meta new file mode 100644 index 0000000..8fb10f3 --- /dev/null +++ b/Editor/Meta/UnityAOTAssemblyResolver.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 029bc0368e1ada342aa29a18d4fae879 +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 index 2e747c7..35af9f2 100644 --- a/Editor/Meta/UnityPluginAssemblyResolver.cs +++ b/Editor/Meta/UnityPluginAssemblyResolver.cs @@ -30,7 +30,7 @@ namespace HybridCLR.Editor.Meta { if (Path.GetFileNameWithoutExtension(dll) == assemblyName && IsPluginDll(dll)) { - Debug.Log($"plugin:{dll}"); + Debug.Log($"UnityPluginAssemblyResolver.ResolveAssembly:{dll}"); return dll; } } diff --git a/Editor/MetaUtil.cs b/Editor/MetaUtil.cs index 24fd7fa..b1ed9b6 100644 --- a/Editor/MetaUtil.cs +++ b/Editor/MetaUtil.cs @@ -29,7 +29,7 @@ namespace HybridCLR.Editor return typeSig; } var a = typeSig.RemovePinnedAndModifiers(); - switch (typeSig.ElementType) + switch (a.ElementType) { case ElementType.Void: return corTypes.Void; case ElementType.Boolean: return corTypes.Byte; @@ -87,6 +87,7 @@ namespace HybridCLR.Editor return new CombinedAssemblyResolver(new PathAssemblyResolver( SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target)), new UnityPluginAssemblyResolver(), + new UnityAOTAssemblyResolver(), new UnityEditorAssemblyResolver()); } } diff --git a/Editor/MethodBridge/Analyzer.cs b/Editor/MethodBridge/Analyzer.cs index 29cbae9..5cdd9e8 100644 --- a/Editor/MethodBridge/Analyzer.cs +++ b/Editor/MethodBridge/Analyzer.cs @@ -118,7 +118,7 @@ namespace HybridCLR.Editor.MethodBridge } foreach (var method in typeDef.Methods) { - // 对于带泛型的参数,统率泛型共享为object + // 对于带泛型的参数,统一泛型共享为object _notGenericMethods.Add(method); } } @@ -182,10 +182,10 @@ namespace HybridCLR.Editor.MethodBridge _newMethods = temp; _newMethods.Clear(); - Task.WhenAll(_processingMethods.Select(method => Task.Run(() => + Task.WaitAll(_processingMethods.Select(method => Task.Run(() => { _methodReferenceAnalyzer.WalkMethod(method.Method, method.KlassInst, method.MethodInst); - }))); + })).ToArray()); Debug.Log($"iteration:[{i}] allMethods:{_notGenericMethods.Count} genericClass:{_genericTypes.Count} genericMethods:{_genericMethods.Count} newMethods:{_newMethods.Count}"); } } diff --git a/package.json b/package.json index 3f00ce1..cadce58 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.focus-creative-games.hybridclr_unity", - "version": "0.4.0", + "version": "0.4.1", "displayName": "HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "category": "Runtime",