Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 82e52de

Browse files
committed
Cleanup and fix Singleton search slightly
1 parent 28181e2 commit 82e52de

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

src/UI/Modules/SearchPage.cs

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ internal void OnSearchClicked()
248248
UnityObjectSearch();
249249

250250
RefreshResultList();
251+
252+
if (m_results.Length > 0)
253+
m_resultCountText.text = $"{m_results.Length} Results";
254+
else
255+
m_resultCountText.text = "No results...";
251256
}
252257

253258
internal void StaticClassSearch()
@@ -274,6 +279,20 @@ internal void StaticClassSearch()
274279
m_results = list.ToArray();
275280
}
276281

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+
277296
private void SingletonSearch()
278297
{
279298
m_isStaticClassSearching = false;
@@ -284,6 +303,8 @@ private void SingletonSearch()
284303
if (!string.IsNullOrEmpty(m_nameInput.text))
285304
nameFilter = m_nameInput.text.ToLower();
286305

306+
var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
307+
287308
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
288309
{
289310
// All non-static classes
@@ -293,31 +314,36 @@ private void SingletonSearch()
293314
{
294315
if (!string.IsNullOrEmpty(nameFilter) && !type.FullName.ToLower().Contains(nameFilter))
295316
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)
301321
{
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+
}
305332
}
306-
else
333+
#endif
334+
// Look for a typical Instance backing field.
335+
FieldInfo fi;
336+
foreach (var name in s_instanceNames)
307337
{
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)
319340
{
320341
var instance = fi.GetValue(null);
342+
if (instance != null)
343+
{
344+
instances.Add(instance);
345+
continue;
346+
}
321347
}
322348
}
323349
}
@@ -444,11 +470,6 @@ internal void UnityObjectSearch()
444470
}
445471

446472
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...";
452473
}
453474

454475
private void OnResultPageTurn()

0 commit comments

Comments
 (0)