[opt] 生成link.xml时扫描除了场景以外的所有资源,收集所有UnityEngine.Object类型引用

main
walon 2022-10-14 18:51:19 +08:00
parent 4a00e944a6
commit 63f1d3b2e4
2 changed files with 47 additions and 1 deletions

View File

@ -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<string, ModuleDefMD> mods, HashSet<TypeRef> typeRefs)
{
var objTypes = new HashSet<Type>();
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}");
}
}
}
}
}

View File

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