public static List <GameObject> GetGameObjectsWithFieldTypes(List <Type> fieldTypes, bool includeInactive) { List <GameObject> results = new List <GameObject>(); List <Component> allComponents = FindObjectsOfType <Component>(includeInactive); foreach (Component component in allComponents) { if (results.Contains(component.gameObject)) { continue; } List <FieldInfo> fields = ReflectionHelper.GetFieldsForType(component.GetType()); bool found = fields.FirstOrDefault(field => fieldTypes.Contains(field.FieldType)) != null; if (found) { results.Add(component.gameObject); } } return(results); }
public static List <GameObject> GetGameObjectsWithFieldName(string fieldName, bool caseSensitive, bool includeInactive, bool matchWholeWord) { fieldName = fieldName.Trim(); List <GameObject> results = new List <GameObject>(); List <Component> allComponents = FindObjectsOfType <Component>(includeInactive); foreach (Component component in allComponents) { if (results.Contains(component.gameObject)) { continue; } List <FieldInfo> fields = ReflectionHelper.GetFieldsForType(component.GetType()); bool found = fields.FirstOrDefault(field => StringMatchHelper.DoesNameMatch(field.Name, fieldName, caseSensitive, matchWholeWord)) != null; if (found) { results.Add(component.gameObject); } } return(results); }