11using System ;
22using System . Collections . Generic ;
3+ using System . IO ;
34using System . Linq ;
45using System . Reflection ;
56using System . Text ;
@@ -21,12 +22,43 @@ public Analyzer(IAssemblyResolver resolver)
2122 _resolver = resolver ;
2223 }
2324
24- public HashSet < TypeRef > CollectRefs ( List < string > rootAssemblies )
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+ ModuleDefMD mod = assCollector . LoadModuleFromFileWithoutCache ( unityEngineDll ) ;
47+ foreach ( TypeDef type in mod . GetTypes ( ) )
48+ {
49+ if ( type . Methods . Any ( m => m . IsInternalCall || m . IsPinvokeImpl ) )
50+ {
51+ preservedTypes . Add ( type ) ;
52+ }
53+ }
54+ }
55+ }
56+
57+ public void CollectHotUpdateRefs ( List < string > rootAssemblies , HashSet < ITypeDefOrRef > preservedTypes )
2558 {
2659 var assCollector = new AssemblyCache ( _resolver ) ;
2760 var rootAssemblyNames = new HashSet < string > ( rootAssemblies ) ;
2861
29- var typeRefs = new HashSet < TypeRef > ( TypeEqualityComparer . Instance ) ;
3062 foreach ( var rootAss in rootAssemblies )
3163 {
3264 var dnAss = assCollector . LoadModule ( rootAss , false ) ;
@@ -39,11 +71,10 @@ public HashSet<TypeRef> CollectRefs(List<string> rootAssemblies)
3971 }
4072 if ( ! rootAssemblyNames . Contains ( type . DefinitionAssembly . Name . ToString ( ) ) )
4173 {
42- typeRefs . Add ( type ) ;
74+ preservedTypes . Add ( type ) ;
4375 }
4476 }
4577 }
46- return typeRefs ;
4778 }
4879 }
4980}
0 commit comments