11using System ;
22using System . Collections . Generic ;
3- using System . IO ;
43using System . Linq ;
54using System . Reflection ;
65using System . Text ;
@@ -22,48 +21,12 @@ public Analyzer(IAssemblyResolver resolver)
2221 _resolver = resolver ;
2322 }
2423
25-
26- public HashSet < ITypeDefOrRef > CollectRefs ( List < string > rootAssemblies , bool includeUnityEngineCoreTypes )
27- {
28- var typeRefs = new HashSet < ITypeDefOrRef > ( TypeEqualityComparer . Instance ) ;
29- CollectHotUpdateRefs ( rootAssemblies , typeRefs ) ;
30-
31- if ( includeUnityEngineCoreTypes )
32- {
33- CollectUnityEngineCoreTypes ( typeRefs ) ;
34- }
35- return typeRefs ;
36- }
37-
38- private void CollectUnityEngineCoreTypes ( HashSet < ITypeDefOrRef > preservedTypes )
39- {
40- Debug . Log ( "CollectUnityEngineCoreTypes" ) ;
41- string unityEngineDllPath = $ "{ EditorApplication . applicationContentsPath } /Managed/UnityEngine";
42-
43- var assCollector = new AssemblyCache ( _resolver ) ;
44- foreach ( string unityEngineDll in Directory . GetFiles ( unityEngineDllPath , "UnityEngine.*.dll" , SearchOption . AllDirectories ) )
45- {
46- // because of bug of unity 2019.4.x, preserving types in this dll will cause crash in android build
47- if ( unityEngineDll . EndsWith ( "UnityEngine.PerformanceReportingModule.dll" , StringComparison . InvariantCulture ) )
48- {
49- continue ;
50- }
51- ModuleDefMD mod = assCollector . LoadModuleFromFileWithoutCache ( unityEngineDll ) ;
52- foreach ( TypeDef type in mod . GetTypes ( ) )
53- {
54- if ( type . Methods . Any ( m => m . IsInternalCall || m . IsPinvokeImpl ) )
55- {
56- preservedTypes . Add ( type ) ;
57- }
58- }
59- }
60- }
61-
62- public void CollectHotUpdateRefs ( List < string > rootAssemblies , HashSet < ITypeDefOrRef > preservedTypes )
24+ public HashSet < TypeRef > CollectRefs ( List < string > rootAssemblies )
6325 {
6426 var assCollector = new AssemblyCache ( _resolver ) ;
6527 var rootAssemblyNames = new HashSet < string > ( rootAssemblies ) ;
6628
29+ var typeRefs = new HashSet < TypeRef > ( TypeEqualityComparer . Instance ) ;
6730 foreach ( var rootAss in rootAssemblies )
6831 {
6932 var dnAss = assCollector . LoadModule ( rootAss , false ) ;
@@ -76,10 +39,11 @@ public void CollectHotUpdateRefs(List<string> rootAssemblies, HashSet<ITypeDefOr
7639 }
7740 if ( ! rootAssemblyNames . Contains ( type . DefinitionAssembly . Name . ToString ( ) ) )
7841 {
79- preservedTypes . Add ( type ) ;
42+ typeRefs . Add ( type ) ;
8043 }
8144 }
8245 }
46+ return typeRefs ;
8347 }
8448 }
8549}
0 commit comments