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