public static GameObject[] GetSceneObjects(bool includeEnabled = true, bool includeDisabled = true) { if (Application.isLoadingLevel) { return(new GameObject[0]); } if (!Locate.cleanGameObjects) { Locate.Build <Transform>(); } if (includeEnabled && includeDisabled) { return(Locate.sceneObjects); } if (!includeEnabled) { return(Locate.disabledObjects); } return(Locate.enabledObjects); }
//===================== // Components //===================== public static Type[] GetSceneComponents <Type>(bool includeEnabled = true, bool includeDisabled = true) where Type : Component { if (Application.isLoadingLevel) { return(new Type[0]); } if (!Locate.cleanSceneComponents.Contains(typeof(Type))) { Locate.Build <Type>(); } if (includeEnabled && includeDisabled) { return((Type[])Locate.sceneComponents[typeof(Type)]); } if (!includeEnabled) { return((Type[])Locate.disabledComponents[typeof(Type)]); } return((Type[])Locate.enabledComponents[typeof(Type)]); }
public static GameObject[] GetSiblings(this GameObject current, bool includeEnabled = true, bool includeDisabled = true, bool includeSelf = true) { if (Application.isLoadingLevel) { return(new GameObject[0]); } if (!Locate.cleanSiblings.Contains(current)) { GameObject parent = current.GetParent(); List <GameObject> siblings; if (parent.IsNull()) { Locate.GetSceneObjects(includeEnabled, includeDisabled); siblings = Locate.rootObjects.Remove(current).ToList(); } else { siblings = parent.GetComponentsInChildren <Transform>(true).Select(x => x.gameObject).ToList(); siblings.RemoveAll(x => x.GetParent() != parent); } Locate.siblings[current] = siblings.ToArray(); Locate.enabledSiblings[current] = Locate.siblings[current].Where(x => !x.IsNull() && x.gameObject.activeInHierarchy).Select(x => x.gameObject).ToArray(); Locate.disabledSiblings[current] = Locate.siblings[current].Where(x => !x.IsNull() && !x.gameObject.activeInHierarchy).Select(x => x.gameObject).ToArray(); Locate.cleanSiblings.Add(current); } GameObject[] results = Locate.enabledSiblings[current]; if (includeEnabled && includeDisabled) { results = Locate.siblings[current]; } if (!includeEnabled) { results = Locate.disabledSiblings[current]; } if (!includeSelf) { results = results.Remove(current); } return(results); }
public static int GetSiblingCount(this GameObject current, bool includeInactive = false) { return(Locate.GetSiblings(current, true, includeInactive).Length); }