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 static Component[] GetComponentsFromSerializedProperty(SerializedProperty property, System.Type restrictionType, bool forceSelfOnly, bool searchChildren, bool allowProxy) { if (!ComponentUtil.IsAcceptableComponentType(restrictionType)) { return(ArrayUtil.Empty <Component>()); } var go = GetGameObjectFromSource(property, forceSelfOnly); if (go == null) { return(ArrayUtil.Empty <Component>()); } if (allowProxy) { if (searchChildren) { return((from c in go.GetComponentsInChildren <Component>() where ObjUtil.IsType(c, restrictionType) || c is IProxy select c).ToArray()); } else { return((from c in go.GetComponents <Component>() where ObjUtil.IsType(c, restrictionType) || c is IProxy select c).ToArray()); } } else { if (searchChildren) { return(go.GetComponentsInChildren(restrictionType)); } else { return(go.GetComponents(restrictionType)); } } }
private UnityEngine.Object GetTargetFromSource(UnityEngine.Object obj) { if (obj == null) { return(null); } if (ObjUtil.IsType(obj, this.RestrictionType)) { return(obj); } if (this.AllowProxy && obj is IProxy) { return(obj); } var go = GameObjectUtil.GetGameObjectFromSource(obj); var o = ObjUtil.GetAsFromSource(this.RestrictionType, obj) as UnityEngine.Object; if (this.SearchChildren && o == null && go != null) { o = go.GetComponentInChildren(this.RestrictionType); } if (this.AllowProxy && o == null && go != null) { if (this.SearchChildren) { o = go.GetComponentInChildren <IProxy>() as Component; } else { o = go.GetComponent <IProxy>() as Component; } } return(o); }