Skip to main content

ComponentGroup<T>

A class in Root.Township, the global namespace.

A component that keeps a list of other components of one type, usually filled from its children in the editor. ColliderGroup builds on it.

Constructors​

MemberWhat it is
ComponentGroup()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
protected List<T> componentsThe backing list.
3 private and internal fields
MemberWhat it is
private List<T> componentsToIgnoreWhenAddingComponents left out when collecting from children.
private bool isAddingComponentsInspector button flag for adding components in children.
private List<Transform> parentsToIgnoreWhenAddingChild transforms whose subtree is skipped when collecting.

Properties​

MemberWhat it is
List<T> Components { get; }The list of grouped components.
int Count { get; }Number of grouped components.

Events​

MemberWhat it is
event ComponentGroup<T> ItemAddedRaised when Add adds an item.
event ComponentGroup<T> ItemRemovedRaised when Remove removes an item.

Methods​

MemberWhat it is
void Add(T item)Adds an item if it is not already in the list and raises ItemAdded.
virtual void GetChildComponents(bool isAddingOn = false)Fills the list from this object and its children, skipping ignored components and parents. Can add to the existing list.
void Remove(T item)Removes an item and raises ItemRemoved if it was there.
void RemoveNullComponents()Removes destroyed or missing entries from the list.
protected virtual bool IsElementValid(T element)Filter used by GetChildComponents. Accepts everything by default.
protected virtual void OnValidate()Editor hook. Empty in the base class.
3 private and internal methods
MemberWhat it is
private IEnumerator System.Collections.IEnumerable.GetEnumerator()Enumerates the components in the group.
private void IBuildRendererPostBake.PostBake()Build step: removes null entries from the list.
private void RecursivlyAddComponents(Transform transform)Adds every valid T on a transform and its children, skipping the ignore lists.

Used in​

Members of other types that take, return or hold a ComponentGroup&lt;T>: