@@ -248,6 +248,11 @@ internal void OnSearchClicked()
248
248
UnityObjectSearch ( ) ;
249
249
250
250
RefreshResultList ( ) ;
251
+
252
+ if ( m_results . Length > 0 )
253
+ m_resultCountText . text = $ "{ m_results . Length } Results";
254
+ else
255
+ m_resultCountText . text = "No results..." ;
251
256
}
252
257
253
258
internal void StaticClassSearch ( )
@@ -274,6 +279,20 @@ internal void StaticClassSearch()
274
279
m_results = list . ToArray ( ) ;
275
280
}
276
281
282
+ internal string [ ] s_instanceNames = new string [ ]
283
+ {
284
+ "m_instance" ,
285
+ "m_Instance" ,
286
+ "s_instance" ,
287
+ "s_Instance" ,
288
+ "_instance" ,
289
+ "_Instance" ,
290
+ "instance" ,
291
+ "Instance" ,
292
+ "<Instance>k__BackingField" ,
293
+ "<instance>k__BackingField" ,
294
+ } ;
295
+
277
296
private void SingletonSearch ( )
278
297
{
279
298
m_isStaticClassSearching = false ;
@@ -284,6 +303,8 @@ private void SingletonSearch()
284
303
if ( ! string . IsNullOrEmpty ( m_nameInput . text ) )
285
304
nameFilter = m_nameInput . text . ToLower ( ) ;
286
305
306
+ var flags = BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Static ;
307
+
287
308
foreach ( var asm in AppDomain . CurrentDomain . GetAssemblies ( ) )
288
309
{
289
310
// All non-static classes
@@ -293,31 +314,36 @@ private void SingletonSearch()
293
314
{
294
315
if ( ! string . IsNullOrEmpty ( nameFilter ) && ! type . FullName . ToLower ( ) . Contains ( nameFilter ) )
295
316
continue ;
296
-
297
- // First look for an "Instance" Property
298
- if ( type . GetProperty ( "Instance" , ReflectionHelpers . CommonFlags ) is PropertyInfo pi
299
- && pi . CanRead
300
- && pi . GetGetMethod ( true ) . IsStatic )
317
+ #if CPP
318
+ // Only look for Properties in IL2CPP, not for Mono.
319
+ PropertyInfo pi ;
320
+ foreach ( var name in s_instanceNames )
301
321
{
302
- var instance = pi . GetValue ( null , null ) ;
303
- if ( instance != null )
304
- instances . Add ( instance ) ;
322
+ pi = type . GetProperty ( name , flags ) ;
323
+ if ( pi != null )
324
+ {
325
+ var instance = pi . GetValue ( null , null ) ;
326
+ if ( instance != null )
327
+ {
328
+ instances . Add ( instance ) ;
329
+ continue ;
330
+ }
331
+ }
305
332
}
306
- else
333
+ #endif
334
+ // Look for a typical Instance backing field.
335
+ FieldInfo fi ;
336
+ foreach ( var name in s_instanceNames )
307
337
{
308
- // Otherwise, look for a typical Instance backing field.
309
- FieldInfo fi ;
310
- fi = type . GetField ( "m_instance" , ReflectionHelpers . CommonFlags ) ;
311
- if ( fi == null )
312
- fi = type . GetField ( "s_instance" , ReflectionHelpers . CommonFlags ) ;
313
- if ( fi == null )
314
- fi = type . GetField ( "_instance" , ReflectionHelpers . CommonFlags ) ;
315
- if ( fi == null )
316
- fi = type . GetField ( "instance" , ReflectionHelpers . CommonFlags ) ;
317
-
318
- if ( fi != null && fi . IsStatic )
338
+ fi = type . GetField ( name , flags ) ;
339
+ if ( fi != null )
319
340
{
320
341
var instance = fi . GetValue ( null ) ;
342
+ if ( instance != null )
343
+ {
344
+ instances . Add ( instance ) ;
345
+ continue ;
346
+ }
321
347
}
322
348
}
323
349
}
@@ -444,11 +470,6 @@ internal void UnityObjectSearch()
444
470
}
445
471
446
472
m_results = results . ToArray ( ) ;
447
-
448
- if ( m_results . Length > 0 )
449
- m_resultCountText . text = $ "{ m_results . Length } Results";
450
- else
451
- m_resultCountText . text = "No results..." ;
452
473
}
453
474
454
475
private void OnResultPageTurn ( )
0 commit comments