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

Commit 5427312

Browse files
committed
Filter UnityExplorer objects from search results
1 parent eb7e80d commit 5427312

File tree

1 file changed

+40
-49
lines changed

1 file changed

+40
-49
lines changed

src/UI/ObjectExplorer/SearchProvider.cs

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -58,39 +58,22 @@ internal static List<object> UnityObjectSearch(string input, string customTypeIn
5858
{
5959
var results = new List<object>();
6060

61-
Type searchType;
62-
switch (context)
61+
Type searchType = null;
62+
if (!string.IsNullOrEmpty(customTypeInput))
6363
{
64-
//case SearchContext.GameObject:
65-
// searchType = typeof(GameObject);
66-
// break;
67-
68-
case SearchContext.UnityObject:
69-
default:
70-
71-
if (!string.IsNullOrEmpty(customTypeInput))
72-
{
73-
if (ReflectionUtility.GetTypeByName(customTypeInput) is Type customType)
74-
{
75-
if (typeof(UnityEngine.Object).IsAssignableFrom(customType))
76-
{
77-
searchType = customType;
78-
break;
79-
}
80-
else
81-
ExplorerCore.LogWarning($"Custom type '{customType.FullName}' is not assignable from UnityEngine.Object!");
82-
}
83-
else
84-
ExplorerCore.LogWarning($"Could not find any type by name '{customTypeInput}'!");
85-
}
86-
87-
searchType = typeof(UnityEngine.Object);
88-
break;
64+
if (ReflectionUtility.GetTypeByName(customTypeInput) is Type customType)
65+
{
66+
if (typeof(UnityEngine.Object).IsAssignableFrom(customType))
67+
searchType = customType;
68+
else
69+
ExplorerCore.LogWarning($"Custom type '{customType.FullName}' is not assignable from UnityEngine.Object!");
70+
}
71+
else
72+
ExplorerCore.LogWarning($"Could not find any type by name '{customTypeInput}'!");
8973
}
9074

91-
9275
if (searchType == null)
93-
return results;
76+
searchType = typeof(UnityEngine.Object);
9477

9578
var allObjects = RuntimeProvider.Instance.FindObjectsOfTypeAll(searchType);
9679

@@ -100,39 +83,47 @@ internal static List<object> UnityObjectSearch(string input, string customTypeIn
10083
if (!string.IsNullOrEmpty(input))
10184
nameFilter = input;
10285

103-
bool canGetGameObject = searchType == typeof(GameObject) || typeof(Component).IsAssignableFrom(searchType);
86+
bool shouldFilterGOs = searchType == typeof(GameObject) || typeof(Component).IsAssignableFrom(searchType);
10487

10588
foreach (var obj in allObjects)
10689
{
10790
// name check
10891
if (!string.IsNullOrEmpty(nameFilter) && !obj.name.ContainsIgnoreCase(nameFilter))
10992
continue;
11093

111-
if (canGetGameObject)
94+
var type = obj.GetActualType();
95+
if (type == typeof(GameObject) || typeof(Component).IsAssignableFrom(type))
11296
{
113-
var go = searchType == typeof(GameObject)
114-
? obj.TryCast<GameObject>()
115-
: obj.TryCast<Component>().gameObject;
97+
GameObject go = type == typeof(GameObject)
98+
? obj.TryCast<GameObject>()
99+
: obj.TryCast<Component>()?.gameObject;
116100

117101
if (go)
118102
{
119-
// scene check
120-
if (sceneFilter != SceneFilter.Any)
121-
{
122-
if (!Filter(go.scene, sceneFilter))
123-
continue;
124-
}
103+
// hide unityexplorer objects
104+
if (go.transform.root.name == "ExplorerCanvas")
105+
continue;
125106

126-
if (childFilter != ChildFilter.Any)
107+
if (shouldFilterGOs)
127108
{
128-
if (!go)
129-
continue;
130-
131-
// root object check (no parent)
132-
if (childFilter == ChildFilter.HasParent && !go.transform.parent)
133-
continue;
134-
else if (childFilter == ChildFilter.RootObject && go.transform.parent)
135-
continue;
109+
// scene check
110+
if (sceneFilter != SceneFilter.Any)
111+
{
112+
if (!Filter(go.scene, sceneFilter))
113+
continue;
114+
}
115+
116+
if (childFilter != ChildFilter.Any)
117+
{
118+
if (!go)
119+
continue;
120+
121+
// root object check (no parent)
122+
if (childFilter == ChildFilter.HasParent && !go.transform.parent)
123+
continue;
124+
else if (childFilter == ChildFilter.RootObject && go.transform.parent)
125+
continue;
126+
}
136127
}
137128
}
138129
}

0 commit comments

Comments
 (0)