From 63f1d3b2e4ae0e3bacdcff6a2273c6c1839b48ed Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 14 Oct 2022 18:51:19 +0800 Subject: [PATCH] =?UTF-8?q?[opt]=20=E7=94=9F=E6=88=90link.xml=E6=97=B6?= =?UTF-8?q?=E6=89=AB=E6=8F=8F=E9=99=A4=E4=BA=86=E5=9C=BA=E6=99=AF=E4=BB=A5?= =?UTF-8?q?=E5=A4=96=E7=9A=84=E6=89=80=E6=9C=89=E8=B5=84=E6=BA=90=EF=BC=8C?= =?UTF-8?q?=E6=94=B6=E9=9B=86=E6=89=80=E6=9C=89UnityEngine.Object=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=BC=95=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/Link/Analyzer.cs | 46 +++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Editor/Link/Analyzer.cs b/Editor/Link/Analyzer.cs index 9d416e1..f701c60 100644 --- a/Editor/Link/Analyzer.cs +++ b/Editor/Link/Analyzer.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using dnlib.DotNet; using HybridCLR.Editor.Meta; +using UnityEditor; using IAssemblyResolver = HybridCLR.Editor.Meta.IAssemblyResolver; namespace HybridCLR.Editor.Link @@ -44,9 +45,54 @@ namespace HybridCLR.Editor.Link } } } + + var modsExludeRoots = assCollector.LoadedModules + .Where(e => !rootAssemblyName.Contains(e.Key)) + .ToDictionary(e => e.Key, e => e.Value); + CollectObjectTypeInAssets(modsExludeRoots, typeRefs); + + assCollector.Dispose(); return typeRefs; } } + + public void CollectObjectTypeInAssets(Dictionary mods, HashSet typeRefs) + { + var objTypes = new HashSet(); + string[] guids = AssetDatabase.FindAssets("t:Object", new[] { "Assets" }); + foreach (string guid in guids) + { + string assetPath = AssetDatabase.GUIDToAssetPath(guid); + Type mainAssetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); + if (mainAssetType == typeof(SceneAsset)) + { + + } + else + { + UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetsAtPath(assetPath); + foreach (UnityEngine.Object obj in objs) + { + objTypes.Add(obj.GetType()); + } + } + } + + var importers = mods.ToDictionary(e => e.Key, e => new Importer(e.Value)); + //Debug.Log($"importers count:{importers.Count} importers:{string.Join(",", importers.Keys)}"); + foreach (var type in objTypes) + { + if (importers.TryGetValue(type.Assembly.GetName().Name, out var im)) + { + typeRefs.Add((TypeRef)im.Import(type)); + //Debug.Log($"== add asset type:{type}"); + } + else + { + //Debug.Log($"== ignore asset type:{type} {type.Assembly.GetName().Name}"); + } + } + } } } diff --git a/package.json b/package.json index 3ca0f00..f4ef7ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.focus-creative-games.hybridclr_unity", - "version": "0.4.2", + "version": "0.4.3", "displayName": "HybridCLR", "description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR", "category": "Runtime",