public static Component[] GetComponentsFromSerializedProperty(SerializedProperty property, System.Type[] allowedTypes, System.Type restrictionType, bool forceSelfOnly, bool searchChildren, bool allowProxy) { if (allowedTypes == null || allowedTypes.Length == 0) { return(ArrayUtil.Empty <Component>()); } var go = DefaultComponentChoiceSelector.GetGameObjectFromSource(property, forceSelfOnly); if (go == null) { return(ArrayUtil.Empty <Component>()); } using (var set = com.spacepuppy.Collections.TempCollection.GetSet <Component>()) { if (searchChildren) { foreach (var c in go.GetComponentsInChildren <Component>()) { if (!ObjUtil.IsType(c, restrictionType, allowProxy)) { continue; } foreach (var tp in allowedTypes) { if (ObjUtil.IsType(c, tp, allowProxy)) { set.Add(c); } } } } else { foreach (var c in go.GetComponents <Component>()) { if (!ObjUtil.IsType(c, restrictionType, allowProxy)) { continue; } foreach (var tp in allowedTypes) { if (ObjUtil.IsType(c, tp, allowProxy)) { set.Add(c); } } } } return((from c in set orderby c.GetType().Name select c).ToArray()); } }
public virtual GUIContent[] GetPopupEntries() { //return (from c in components select new GUIContent(c.GetType().Name)).ToArray(); using (var lst = com.spacepuppy.Collections.TempCollection.GetList <GUIContent>()) { lst.Add(new GUIContent("Nothing...")); if (_drawer.SearchChildren) { lst.AddRange(from s in DefaultComponentChoiceSelector.GetUniqueComponentNamesWithOwner(_components) select new GUIContent(s)); } else { lst.AddRange(from s in DefaultComponentChoiceSelector.GetUniqueComponentNames(_components) select new GUIContent(s)); } return(lst.ToArray()); } }