@@ -17,6 +17,8 @@ namespace UnityEditor
17
17
{
18
18
internal partial class AssemblyHelper
19
19
{
20
+ static readonly Type [ ] ExtendableScriptTypes = { typeof ( MonoBehaviour ) , typeof ( ScriptableObject ) , typeof ( Experimental . AssetImporters . ScriptedImporter ) } ;
21
+
20
22
// Check if assmebly internal name doesn't match file name, and show the warning.
21
23
static public void CheckForAssemblyFileNameMismatch ( string assemblyPath )
22
24
{
@@ -50,24 +52,6 @@ static public string[] GetNamesOfAssembliesLoadedInCurrentDomain()
50
52
return locations . ToArray ( ) ;
51
53
}
52
54
53
- public static Assembly FindLoadedAssemblyWithName ( string s )
54
- {
55
- var assemblies = AppDomain . CurrentDomain . GetAssemblies ( ) ;
56
- foreach ( var a in assemblies )
57
- {
58
- try
59
- {
60
- if ( s == System . IO . Path . GetFileNameWithoutExtension ( a . Location ) )
61
- return a ;
62
- }
63
- catch ( NotSupportedException )
64
- {
65
- //we have some "dynamic" assmeblies that do not have a filename
66
- }
67
- }
68
- return null ;
69
- }
70
-
71
55
static public string ExtractInternalAssemblyName ( string path )
72
56
{
73
57
try
@@ -222,55 +206,29 @@ static public bool IsUnityEngineModule(Assembly assembly)
222
206
return assembly . GetCustomAttributes ( typeof ( UnityEngineModuleAssembly ) , false ) . Length > 0 ;
223
207
}
224
208
225
- private static bool IsTypeAUserExtendedScript ( AssemblyDefinition assembly , TypeReference type )
209
+ private static bool IsTypeAUserExtendedScript ( TypeReference type )
226
210
{
227
- if ( type == null )
211
+ if ( type == null || type . FullName == "System.Object" )
228
212
return false ;
229
213
230
- // Early out
231
- if ( type . FullName == "System.Object" )
232
- return false ;
233
-
234
- // Look up the type in UnityEngine.dll or UnityEditor.dll
235
- Assembly builtinAssembly = null ;
236
- if ( type . Scope . Name == "UnityEngine" || type . Scope . Name == "UnityEngine.CoreModule" )
237
- builtinAssembly = typeof ( MonoBehaviour ) . Assembly ;
238
- else if ( type . Scope . Name == "UnityEditor" )
239
- builtinAssembly = typeof ( EditorWindow ) . Assembly ;
240
- else if ( type . Scope . Name == "UnityEngine.UI" )
241
- builtinAssembly = FindLoadedAssemblyWithName ( "UnityEngine.UI" ) ;
242
-
243
- if ( builtinAssembly != null )
214
+ foreach ( var extendableScriptType in ExtendableScriptTypes )
244
215
{
245
- // TypeReference.FullName is cached and is preferred to use, but in case of generic types it
246
- // includes generic arguments we can't use to get type from assembly.
247
- var typeName = type . IsGenericInstance ? ( type . Namespace + "." + type . Name ) : type . FullName ;
248
- var engineType = builtinAssembly . GetType ( typeName ) ;
249
-
250
- // TODO: this "list of classes" should get dynamically filled by the classes them self, thus removing dependency of this class on those classes.
251
- if ( engineType != null )
252
- {
253
- if ( engineType == typeof ( MonoBehaviour ) || engineType . IsSubclassOf ( typeof ( MonoBehaviour ) ) )
254
- return true ;
255
- if ( engineType == typeof ( ScriptableObject ) || engineType . IsSubclassOf ( typeof ( ScriptableObject ) ) )
256
- return true ;
257
- if ( engineType == typeof ( Experimental . AssetImporters . ScriptedImporter ) || engineType . IsSubclassOf ( typeof ( Experimental . AssetImporters . ScriptedImporter ) ) )
258
- return true ;
259
- }
216
+ if ( type . Name == extendableScriptType . Name && type . Namespace == extendableScriptType . Namespace )
217
+ return true ;
260
218
}
261
219
262
- TypeDefinition typeDefinition = null ;
263
220
try
264
221
{
265
- typeDefinition = type . Resolve ( ) ;
222
+ var typeDefinition = type . Resolve ( ) ;
223
+
224
+ if ( typeDefinition != null )
225
+ return IsTypeAUserExtendedScript ( typeDefinition . BaseType ) ;
266
226
}
267
227
catch ( AssemblyResolutionException )
268
228
{
269
229
// just eat exception if we fail to load assembly here.
270
230
// failure should be handled better in other places.
271
231
}
272
- if ( typeDefinition != null )
273
- return IsTypeAUserExtendedScript ( assembly , typeDefinition . BaseType ) ;
274
232
275
233
return false ;
276
234
}
@@ -308,7 +266,7 @@ public static void ExtractAllClassesThatAreUserExtendedScripts(string path, out
308
266
309
267
try
310
268
{
311
- if ( IsTypeAUserExtendedScript ( assembly , baseType ) )
269
+ if ( IsTypeAUserExtendedScript ( baseType ) )
312
270
{
313
271
classNames . Add ( type . Name ) ;
314
272
nameSpaces . Add ( type . Namespace ) ;
0 commit comments