[new] HybridCLRSettings新增collectAssetReferenceTypes字段指示生成link.xml是否扫描资源中引用的类型

main
walon 2022-10-14 23:20:35 +08:00
parent a74130618e
commit d7a1765146
5 changed files with 23 additions and 10 deletions

View File

@ -45,7 +45,7 @@ namespace HybridCLR.Editor.Commands
} }
} }
var analyzer = new Analyzer(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget)); var analyzer = new Analyzer(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), HybridCLRSettings.Instance.collectAssetReferenceTypes);
var refTypes = analyzer.CollectRefs(hotfixAssembles); var refTypes = analyzer.CollectRefs(hotfixAssembles);
Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssembles.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}"); Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssembles.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}");

View File

@ -14,10 +14,12 @@ namespace HybridCLR.Editor.Link
public class Analyzer public class Analyzer
{ {
private readonly IAssemblyResolver _resolver; private readonly IAssemblyResolver _resolver;
private readonly bool _analyzeAssetType;
public Analyzer(IAssemblyResolver resolver) public Analyzer(IAssemblyResolver resolver, bool analyzeAssetType)
{ {
_resolver = resolver; _resolver = resolver;
_analyzeAssetType = analyzeAssetType;
} }
public HashSet<TypeRef> CollectRefs(List<Assembly> rootAssemblies) public HashSet<TypeRef> CollectRefs(List<Assembly> rootAssemblies)
@ -46,11 +48,13 @@ namespace HybridCLR.Editor.Link
} }
} }
if (_analyzeAssetType)
{
var modsExludeRoots = assCollector.LoadedModules var modsExludeRoots = assCollector.LoadedModules
.Where(e => !rootAssemblyName.Contains(e.Key)) .Where(e => !rootAssemblyName.Contains(e.Key))
.ToDictionary(e => e.Key, e => e.Value); .ToDictionary(e => e.Key, e => e.Value);
CollectObjectTypeInAssets(modsExludeRoots, typeRefs); CollectObjectTypeInAssets(modsExludeRoots, typeRefs);
}
assCollector.Dispose(); assCollector.Dispose();
return typeRefs; return typeRefs;
@ -73,11 +77,14 @@ namespace HybridCLR.Editor.Link
{ {
UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetsAtPath(assetPath); UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetsAtPath(assetPath);
foreach (UnityEngine.Object obj in objs) foreach (UnityEngine.Object obj in objs)
{
if (obj != null)
{ {
objTypes.Add(obj.GetType()); objTypes.Add(obj.GetType());
} }
} }
} }
}
var importers = mods.ToDictionary(e => e.Key, e => new Importer(e.Value)); var importers = mods.ToDictionary(e => e.Key, e => new Importer(e.Value));
//Debug.Log($"importers count:{importers.Count} importers:{string.Join(",", importers.Keys)}"); //Debug.Log($"importers count:{importers.Count} importers:{string.Join(",", importers.Keys)}");

View File

@ -14,6 +14,7 @@ namespace HybridCLR.Editor
private SerializedProperty m_CloneFromGitee; private SerializedProperty m_CloneFromGitee;
private SerializedProperty m_HotUpdateAssemblyDefinitions; private SerializedProperty m_HotUpdateAssemblyDefinitions;
private SerializedProperty m_HotUpdateAssemblies; private SerializedProperty m_HotUpdateAssemblies;
private SerializedProperty m_collectAssetReferenceTypes;
private SerializedProperty m_OutputLinkFile; private SerializedProperty m_OutputLinkFile;
private SerializedProperty m_OutputAOTGenericReferenceFile; private SerializedProperty m_OutputAOTGenericReferenceFile;
private SerializedProperty m_MaxGenericReferenceIteration; private SerializedProperty m_MaxGenericReferenceIteration;
@ -32,6 +33,7 @@ namespace HybridCLR.Editor
m_CloneFromGitee = m_SerializedObject.FindProperty("cloneFromGitee"); m_CloneFromGitee = m_SerializedObject.FindProperty("cloneFromGitee");
m_HotUpdateAssemblyDefinitions = m_SerializedObject.FindProperty("hotUpdateAssemblyDefinitions"); m_HotUpdateAssemblyDefinitions = m_SerializedObject.FindProperty("hotUpdateAssemblyDefinitions");
m_HotUpdateAssemblies = m_SerializedObject.FindProperty("hotUpdateAssemblies"); m_HotUpdateAssemblies = m_SerializedObject.FindProperty("hotUpdateAssemblies");
m_collectAssetReferenceTypes = m_SerializedObject.FindProperty("collectAssetReferenceTypes");
m_OutputLinkFile = m_SerializedObject.FindProperty("outputLinkFile"); m_OutputLinkFile = m_SerializedObject.FindProperty("outputLinkFile");
m_OutputAOTGenericReferenceFile = m_SerializedObject.FindProperty("outputAOTGenericReferenceFile"); m_OutputAOTGenericReferenceFile = m_SerializedObject.FindProperty("outputAOTGenericReferenceFile");
m_MaxGenericReferenceIteration = m_SerializedObject.FindProperty("maxGenericReferenceIteration"); m_MaxGenericReferenceIteration = m_SerializedObject.FindProperty("maxGenericReferenceIteration");
@ -104,6 +106,7 @@ namespace HybridCLR.Editor
EditorGUILayout.PropertyField(m_UseGlobalIl2cpp); EditorGUILayout.PropertyField(m_UseGlobalIl2cpp);
EditorGUILayout.PropertyField(m_HotUpdateAssemblyDefinitions); EditorGUILayout.PropertyField(m_HotUpdateAssemblyDefinitions);
EditorGUILayout.PropertyField(m_HotUpdateAssemblies); EditorGUILayout.PropertyField(m_HotUpdateAssemblies);
EditorGUILayout.PropertyField(m_collectAssetReferenceTypes);
EditorGUILayout.PropertyField(m_OutputLinkFile); EditorGUILayout.PropertyField(m_OutputLinkFile);
EditorGUILayout.PropertyField(m_OutputAOTGenericReferenceFile); EditorGUILayout.PropertyField(m_OutputAOTGenericReferenceFile);
EditorGUILayout.PropertyField(m_MaxGenericReferenceIteration); EditorGUILayout.PropertyField(m_MaxGenericReferenceIteration);

View File

@ -20,7 +20,10 @@ namespace HybridCLR.Editor
[Header("热更新dlls")] [Header("热更新dlls")]
public string[] hotUpdateAssemblies; public string[] hotUpdateAssemblies;
[Header("自动扫描生成的link.xml路径")] [Header("生成link.xml时扫描asset中引用的类型")]
public bool collectAssetReferenceTypes;
[Header("生成的link.xml路径")]
public string outputLinkFile = "HybridCLRData/Generated/link.xml"; public string outputLinkFile = "HybridCLRData/Generated/link.xml";
[Header("自动扫描生成的AOTGenericReferences.cs路径")] [Header("自动扫描生成的AOTGenericReferences.cs路径")]

View File

@ -1,6 +1,6 @@
{ {
"name": "com.focus-creative-games.hybridclr_unity", "name": "com.focus-creative-games.hybridclr_unity",
"version": "0.4.4", "version": "0.4.5",
"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",