Class GameObjectExtensions
Extension methods for GameObject and Transform operations.
Namespace: NWH.Common.Utility
Assembly: NWH.Common.dll
Syntax
public static class GameObjectExtensions
Methods
| Edit this page View SourceFindBoundsIncludeChildren(GameObject)
Calculates the combined bounds of all MeshRenderers in a GameObject and its children.
Declaration
public static Bounds FindBoundsIncludeChildren(this GameObject gameObject)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | gameObject | GameObject to calculate bounds for. |
Returns
| Type | Description |
|---|---|
| Bounds | Combined bounds encapsulating all child renderers. |
GetComponentInParent<T>(Transform, bool)
Searches for a component in parent GameObjects, with option to include inactive objects. More flexible than Unity's built-in GetComponentInParent.
Declaration
public static T GetComponentInParent<T>(this Transform transform, bool includeInactive = true) where T : Component
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | Starting transform. |
| bool | includeInactive | Include inactive GameObjects in search. |
Returns
| Type | Description |
|---|---|
| T | First component of type T found in parents, or null if none found. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of component to find. |
GetComponentInParentsOrChildren<T>(Transform, bool)
Searches for a component in parents first, then children if not found. Combines functionality of GetComponentInParent and GetComponentInChildren.
Declaration
public static T GetComponentInParentsOrChildren<T>(this Transform transform, bool includeInactive = true) where T : Component
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | Starting transform. |
| bool | includeInactive | Include inactive GameObjects in search. |
Returns
| Type | Description |
|---|---|
| T | First component of type T found, or null if none found. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of component to find. |