[remove] 移除HybridCLRSettings的collectAssetReferenceTypes选项

main
walon 2023-02-07 12:42:16 +08:00
parent b5a7899657
commit 275a3bd01a
5 changed files with 4 additions and 61 deletions

View File

@ -26,7 +26,7 @@ namespace HybridCLR.Editor.Commands
List<string> hotfixAssemblies = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved; List<string> hotfixAssemblies = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved;
var analyzer = new Analyzer(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotfixAssemblies), HybridCLRSettings.Instance.collectAssetReferenceTypes); var analyzer = new Analyzer(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotfixAssemblies));
var refTypes = analyzer.CollectRefs(hotfixAssemblies); var refTypes = analyzer.CollectRefs(hotfixAssemblies);
Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssemblies.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}"); Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssemblies.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}");

View File

@ -14,12 +14,10 @@ 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, bool analyzeAssetType) public Analyzer(IAssemblyResolver resolver)
{ {
_resolver = resolver; _resolver = resolver;
_analyzeAssetType = analyzeAssetType;
} }
public HashSet<TypeRef> CollectRefs(List<string> rootAssemblies) public HashSet<TypeRef> CollectRefs(List<string> rootAssemblies)
@ -31,7 +29,7 @@ namespace HybridCLR.Editor.Link
var typeRefs = new HashSet<TypeRef>(TypeEqualityComparer.Instance); var typeRefs = new HashSet<TypeRef>(TypeEqualityComparer.Instance);
foreach (var rootAss in rootAssemblies) foreach (var rootAss in rootAssemblies)
{ {
var dnAss = assCollector.LoadModule(rootAss, _analyzeAssetType); var dnAss = assCollector.LoadModule(rootAss, false);
foreach (var type in dnAss.GetTypeRefs()) foreach (var type in dnAss.GetTypeRefs())
{ {
if (!rootAssemblyNames.Contains(type.DefinitionAssembly.Name.ToString())) if (!rootAssemblyNames.Contains(type.DefinitionAssembly.Name.ToString()))
@ -41,58 +39,9 @@ namespace HybridCLR.Editor.Link
} }
} }
if (_analyzeAssetType)
{
var modsExludeRoots = assCollector.LoadedModules
.Where(e => !rootAssemblyNames.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)
{
if (obj != null)
{
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

@ -20,7 +20,6 @@ namespace HybridCLR.Editor
private SerializedProperty _externalHotUpdateAssembliyDirs; private SerializedProperty _externalHotUpdateAssembliyDirs;
private SerializedProperty _strippedAOTDllOutputRootDir; private SerializedProperty _strippedAOTDllOutputRootDir;
private SerializedProperty _patchAOTAssemblies; private SerializedProperty _patchAOTAssemblies;
private SerializedProperty _collectAssetReferenceTypes;
private SerializedProperty _outputLinkFile; private SerializedProperty _outputLinkFile;
private SerializedProperty _outputAOTGenericReferenceFile; private SerializedProperty _outputAOTGenericReferenceFile;
private SerializedProperty _maxGenericReferenceIteration; private SerializedProperty _maxGenericReferenceIteration;
@ -48,7 +47,6 @@ namespace HybridCLR.Editor
_externalHotUpdateAssembliyDirs = _serializedObject.FindProperty("externalHotUpdateAssembliyDirs"); _externalHotUpdateAssembliyDirs = _serializedObject.FindProperty("externalHotUpdateAssembliyDirs");
_strippedAOTDllOutputRootDir = _serializedObject.FindProperty("strippedAOTDllOutputRootDir"); _strippedAOTDllOutputRootDir = _serializedObject.FindProperty("strippedAOTDllOutputRootDir");
_patchAOTAssemblies = _serializedObject.FindProperty("patchAOTAssemblies"); _patchAOTAssemblies = _serializedObject.FindProperty("patchAOTAssemblies");
_collectAssetReferenceTypes = _serializedObject.FindProperty("collectAssetReferenceTypes");
_outputLinkFile = _serializedObject.FindProperty("outputLinkFile"); _outputLinkFile = _serializedObject.FindProperty("outputLinkFile");
_outputAOTGenericReferenceFile = _serializedObject.FindProperty("outputAOTGenericReferenceFile"); _outputAOTGenericReferenceFile = _serializedObject.FindProperty("outputAOTGenericReferenceFile");
_maxGenericReferenceIteration = _serializedObject.FindProperty("maxGenericReferenceIteration"); _maxGenericReferenceIteration = _serializedObject.FindProperty("maxGenericReferenceIteration");
@ -137,7 +135,6 @@ namespace HybridCLR.Editor
EditorGUILayout.PropertyField(_externalHotUpdateAssembliyDirs); EditorGUILayout.PropertyField(_externalHotUpdateAssembliyDirs);
EditorGUILayout.PropertyField(_strippedAOTDllOutputRootDir); EditorGUILayout.PropertyField(_strippedAOTDllOutputRootDir);
EditorGUILayout.PropertyField(_patchAOTAssemblies); EditorGUILayout.PropertyField(_patchAOTAssemblies);
EditorGUILayout.PropertyField(_collectAssetReferenceTypes);
EditorGUILayout.PropertyField(_outputLinkFile); EditorGUILayout.PropertyField(_outputLinkFile);
EditorGUILayout.PropertyField(_outputAOTGenericReferenceFile); EditorGUILayout.PropertyField(_outputAOTGenericReferenceFile);
EditorGUILayout.PropertyField(_maxGenericReferenceIteration); EditorGUILayout.PropertyField(_maxGenericReferenceIteration);

View File

@ -38,9 +38,6 @@ namespace HybridCLR.Editor
[Header("补充元数据AOT dlls")] [Header("补充元数据AOT dlls")]
public string[] patchAOTAssemblies; public string[] patchAOTAssemblies;
[Header("生成link.xml时扫描asset中引用的类型")]
public bool collectAssetReferenceTypes;
[Header("生成的link.xml路径")] [Header("生成的link.xml路径")]
public string outputLinkFile = "HybridCLRData/Generated/link.xml"; public string outputLinkFile = "HybridCLRData/Generated/link.xml";

View File

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