mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-01-08 10:33:52 +08:00
Filter UnityExplorer objects from search results
This commit is contained in:
parent
eb7e80d910
commit
5427312f18
@ -58,39 +58,22 @@ namespace UnityExplorer.UI.ObjectExplorer
|
|||||||
{
|
{
|
||||||
var results = new List<object>();
|
var results = new List<object>();
|
||||||
|
|
||||||
Type searchType;
|
Type searchType = null;
|
||||||
switch (context)
|
if (!string.IsNullOrEmpty(customTypeInput))
|
||||||
{
|
{
|
||||||
//case SearchContext.GameObject:
|
if (ReflectionUtility.GetTypeByName(customTypeInput) is Type customType)
|
||||||
// searchType = typeof(GameObject);
|
{
|
||||||
// break;
|
if (typeof(UnityEngine.Object).IsAssignableFrom(customType))
|
||||||
|
searchType = customType;
|
||||||
case SearchContext.UnityObject:
|
else
|
||||||
default:
|
ExplorerCore.LogWarning($"Custom type '{customType.FullName}' is not assignable from UnityEngine.Object!");
|
||||||
|
}
|
||||||
if (!string.IsNullOrEmpty(customTypeInput))
|
else
|
||||||
{
|
ExplorerCore.LogWarning($"Could not find any type by name '{customTypeInput}'!");
|
||||||
if (ReflectionUtility.GetTypeByName(customTypeInput) is Type customType)
|
|
||||||
{
|
|
||||||
if (typeof(UnityEngine.Object).IsAssignableFrom(customType))
|
|
||||||
{
|
|
||||||
searchType = customType;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ExplorerCore.LogWarning($"Custom type '{customType.FullName}' is not assignable from UnityEngine.Object!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
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,31 +91,39 @@ 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)
|
||||||
{
|
{
|
||||||
// scene check
|
// hide unityexplorer objects
|
||||||
if (sceneFilter != SceneFilter.Any)
|
if (go.transform.root.name == "ExplorerCanvas")
|
||||||
{
|
continue;
|
||||||
if (!Filter(go.scene, sceneFilter))
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (childFilter != ChildFilter.Any)
|
if (shouldFilterGOs)
|
||||||
{
|
{
|
||||||
if (!go)
|
// scene check
|
||||||
continue;
|
if (sceneFilter != SceneFilter.Any)
|
||||||
|
{
|
||||||
|
if (!Filter(go.scene, sceneFilter))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// root object check (no parent)
|
if (childFilter != ChildFilter.Any)
|
||||||
if (childFilter == ChildFilter.HasParent && !go.transform.parent)
|
{
|
||||||
continue;
|
if (!go)
|
||||||
else if (childFilter == ChildFilter.RootObject && go.transform.parent)
|
continue;
|
||||||
continue;
|
|
||||||
|
// root object check (no parent)
|
||||||
|
if (childFilter == ChildFilter.HasParent && !go.transform.parent)
|
||||||
|
continue;
|
||||||
|
else if (childFilter == ChildFilter.RootObject && go.transform.parent)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user