[opt] 生成link.xml时扫描除了场景以外的所有资源,收集所有UnityEngine.Object类型引用
parent
4a00e944a6
commit
63f1d3b2e4
|
@ -6,6 +6,7 @@ using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
using HybridCLR.Editor.Meta;
|
using HybridCLR.Editor.Meta;
|
||||||
|
using UnityEditor;
|
||||||
using IAssemblyResolver = HybridCLR.Editor.Meta.IAssemblyResolver;
|
using IAssemblyResolver = HybridCLR.Editor.Meta.IAssemblyResolver;
|
||||||
|
|
||||||
namespace HybridCLR.Editor.Link
|
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();
|
assCollector.Dispose();
|
||||||
return typeRefs;
|
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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "com.focus-creative-games.hybridclr_unity",
|
"name": "com.focus-creative-games.hybridclr_unity",
|
||||||
"version": "0.4.2",
|
"version": "0.4.3",
|
||||||
"displayName": "HybridCLR",
|
"displayName": "HybridCLR",
|
||||||
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
|
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
|
||||||
"category": "Runtime",
|
"category": "Runtime",
|
||||||
|
|
Loading…
Reference in New Issue