@@ -58,39 +58,22 @@ internal static List<object> UnityObjectSearch(string input, string customTypeIn
58
58
{
59
59
var results = new List < object > ( ) ;
60
60
61
- Type searchType ;
62
- switch ( context )
61
+ Type searchType = null ;
62
+ if ( ! string . IsNullOrEmpty ( customTypeInput ) )
63
63
{
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 } '!") ;
89
73
}
90
74
91
-
92
75
if ( searchType == null )
93
- return results ;
76
+ searchType = typeof ( UnityEngine . Object ) ;
94
77
95
78
var allObjects = RuntimeProvider . Instance . FindObjectsOfTypeAll ( searchType ) ;
96
79
@@ -100,39 +83,47 @@ internal static List<object> UnityObjectSearch(string input, string customTypeIn
100
83
if ( ! string . IsNullOrEmpty ( input ) )
101
84
nameFilter = input ;
102
85
103
- bool canGetGameObject = searchType == typeof ( GameObject ) || typeof ( Component ) . IsAssignableFrom ( searchType ) ;
86
+ bool shouldFilterGOs = searchType == typeof ( GameObject ) || typeof ( Component ) . IsAssignableFrom ( searchType ) ;
104
87
105
88
foreach ( var obj in allObjects )
106
89
{
107
90
// name check
108
91
if ( ! string . IsNullOrEmpty ( nameFilter ) && ! obj . name . ContainsIgnoreCase ( nameFilter ) )
109
92
continue ;
110
93
111
- if ( canGetGameObject )
94
+ var type = obj . GetActualType ( ) ;
95
+ if ( type == typeof ( GameObject ) || typeof ( Component ) . IsAssignableFrom ( type ) )
112
96
{
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 ;
116
100
117
101
if ( go )
118
102
{
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 ;
125
106
126
- if ( childFilter != ChildFilter . Any )
107
+ if ( shouldFilterGOs )
127
108
{
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
+ }
136
127
}
137
128
}
138
129
}
0 commit comments