@@ -96,21 +96,17 @@ private static GameObject matchConditionForProperty(PropertyEqualsCondition prop
9696 int layerId = LayerMask . NameToLayer ( propertyEqualsCondition . PropertyValue ) ;
9797 return gameObjectToCheck . layer . Equals ( layerId ) ? gameObjectToCheck : null ;
9898 case PropertyType . component :
99- var componentName = propertyEqualsCondition . PropertyValue . Split ( new string [ ] { "." } , System . StringSplitOptions . None ) . Last ( ) ;
100- var list = gameObjectToCheck . GetComponents ( typeof ( UnityEngine . Component ) ) ;
101- for ( int i = 0 ; i < list . Length ; i ++ )
99+ var componentNameFromCondition = propertyEqualsCondition . PropertyValue . Split ( new string [ ] { "." } , System . StringSplitOptions . None ) . Last ( ) ;
100+ var allComponents = gameObjectToCheck . GetComponents ( typeof ( Component ) ) ;
101+
102+ foreach ( var comp in allComponents )
102103 {
103- try
104- {
105- if ( componentName . Equals ( list [ i ] . GetType ( ) . Name ) )
106- {
107- return gameObjectToCheck ;
108- }
109- }
110- catch ( System . NullReferenceException )
111- {
112- continue ;
113- }
104+ if ( comp == null ) continue ;
105+ string shortTypeName = getComponentShortName ( comp ) ;
106+ if ( string . IsNullOrEmpty ( shortTypeName ) ) continue ;
107+
108+ if ( componentNameFromCondition . Equals ( shortTypeName ) )
109+ return gameObjectToCheck ;
114110 }
115111 return null ;
116112 case PropertyType . text :
@@ -156,14 +152,17 @@ private static GameObject matchConditionForFunction(FunctionCondition functionCo
156152 string layerNm = LayerMask . LayerToName ( gameObjectToCheck . layer ) ;
157153 return layerNm . Contains ( functionCondition . PropertyValue ) ? gameObjectToCheck : null ;
158154 case PropertyType . component :
159- var componentName = functionCondition . PropertyValue . Split ( new string [ ] { "." } , System . StringSplitOptions . None ) . Last ( ) ;
160- var list = gameObjectToCheck . GetComponents ( typeof ( UnityEngine . Component ) ) ;
161- for ( int i = 0 ; i < list . Length ; i ++ )
155+ var componentNameFromCondition = functionCondition . PropertyValue . Split ( new string [ ] { "." } , System . StringSplitOptions . None ) . Last ( ) ;
156+
157+ var allComponents = gameObjectToCheck . GetComponents ( typeof ( Component ) ) ;
158+
159+ foreach ( var comp in allComponents )
162160 {
163- if ( list [ i ] . GetType ( ) . Name . Contains ( componentName ) )
164- {
161+ if ( comp == null ) continue ;
162+ string shortTypeName = getComponentShortName ( comp ) ;
163+ if ( string . IsNullOrEmpty ( shortTypeName ) ) continue ;
164+ if ( shortTypeName . Contains ( componentNameFromCondition ) )
165165 return gameObjectToCheck ;
166- }
167166 }
168167 return null ;
169168 case PropertyType . text :
@@ -178,6 +177,17 @@ private static GameObject matchConditionForFunction(FunctionCondition functionCo
178177 }
179178 return null ;
180179 }
180+ private static string getComponentShortName ( Component component )
181+ {
182+ string componentToString = component . ToString ( ) ;
183+ int openParen = componentToString . LastIndexOf ( '(' ) ;
184+ int closeParen = componentToString . LastIndexOf ( ')' ) ;
185+
186+ if ( openParen == - 1 || closeParen <= openParen ) return "" ;
187+
188+ string fullTypeName = componentToString . Substring ( openParen + 1 , closeParen - openParen - 1 ) ;
189+ return fullTypeName . Split ( '.' ) . Last ( ) ;
190+ }
181191 private static string getText ( UnityEngine . GameObject objectToCheck )
182192 {
183193 try
0 commit comments