mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-01-09 10:58:57 +08:00
Filter UnityExplorer objects from search results
This commit is contained in:
parent
eb7e80d910
commit
5427312f18
@ -58,25 +58,13 @@ namespace UnityExplorer.UI.ObjectExplorer
|
|||||||
{
|
{
|
||||||
var results = new List<object>();
|
var results = new List<object>();
|
||||||
|
|
||||||
Type searchType;
|
Type searchType = null;
|
||||||
switch (context)
|
|
||||||
{
|
|
||||||
//case SearchContext.GameObject:
|
|
||||||
// searchType = typeof(GameObject);
|
|
||||||
// break;
|
|
||||||
|
|
||||||
case SearchContext.UnityObject:
|
|
||||||
default:
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(customTypeInput))
|
if (!string.IsNullOrEmpty(customTypeInput))
|
||||||
{
|
{
|
||||||
if (ReflectionUtility.GetTypeByName(customTypeInput) is Type customType)
|
if (ReflectionUtility.GetTypeByName(customTypeInput) is Type customType)
|
||||||
{
|
{
|
||||||
if (typeof(UnityEngine.Object).IsAssignableFrom(customType))
|
if (typeof(UnityEngine.Object).IsAssignableFrom(customType))
|
||||||
{
|
|
||||||
searchType = customType;
|
searchType = customType;
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
ExplorerCore.LogWarning($"Custom type '{customType.FullName}' is not assignable from UnityEngine.Object!");
|
ExplorerCore.LogWarning($"Custom type '{customType.FullName}' is not assignable from UnityEngine.Object!");
|
||||||
}
|
}
|
||||||
@ -84,13 +72,8 @@ namespace UnityExplorer.UI.ObjectExplorer
|
|||||||
ExplorerCore.LogWarning($"Could not find any type by name '{customTypeInput}'!");
|
ExplorerCore.LogWarning($"Could not find any type by name '{customTypeInput}'!");
|
||||||
}
|
}
|
||||||
|
|
||||||
searchType = typeof(UnityEngine.Object);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (searchType == null)
|
if (searchType == null)
|
||||||
return results;
|
searchType = typeof(UnityEngine.Object);
|
||||||
|
|
||||||
var allObjects = RuntimeProvider.Instance.FindObjectsOfTypeAll(searchType);
|
var allObjects = RuntimeProvider.Instance.FindObjectsOfTypeAll(searchType);
|
||||||
|
|
||||||
@ -100,7 +83,7 @@ namespace UnityExplorer.UI.ObjectExplorer
|
|||||||
if (!string.IsNullOrEmpty(input))
|
if (!string.IsNullOrEmpty(input))
|
||||||
nameFilter = input;
|
nameFilter = input;
|
||||||
|
|
||||||
bool canGetGameObject = searchType == typeof(GameObject) || typeof(Component).IsAssignableFrom(searchType);
|
bool shouldFilterGOs = searchType == typeof(GameObject) || typeof(Component).IsAssignableFrom(searchType);
|
||||||
|
|
||||||
foreach (var obj in allObjects)
|
foreach (var obj in allObjects)
|
||||||
{
|
{
|
||||||
@ -108,13 +91,20 @@ namespace UnityExplorer.UI.ObjectExplorer
|
|||||||
if (!string.IsNullOrEmpty(nameFilter) && !obj.name.ContainsIgnoreCase(nameFilter))
|
if (!string.IsNullOrEmpty(nameFilter) && !obj.name.ContainsIgnoreCase(nameFilter))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (canGetGameObject)
|
var type = obj.GetActualType();
|
||||||
|
if (type == typeof(GameObject) || typeof(Component).IsAssignableFrom(type))
|
||||||
{
|
{
|
||||||
var go = searchType == typeof(GameObject)
|
GameObject go = type == typeof(GameObject)
|
||||||
? obj.TryCast<GameObject>()
|
? obj.TryCast<GameObject>()
|
||||||
: obj.TryCast<Component>().gameObject;
|
: obj.TryCast<Component>()?.gameObject;
|
||||||
|
|
||||||
if (go)
|
if (go)
|
||||||
|
{
|
||||||
|
// hide unityexplorer objects
|
||||||
|
if (go.transform.root.name == "ExplorerCanvas")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (shouldFilterGOs)
|
||||||
{
|
{
|
||||||
// scene check
|
// scene check
|
||||||
if (sceneFilter != SceneFilter.Any)
|
if (sceneFilter != SceneFilter.Any)
|
||||||
@ -136,6 +126,7 @@ namespace UnityExplorer.UI.ObjectExplorer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
results.Add(obj);
|
results.Add(obj);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user