Class ColliderExtensions
Extension methods for Collider and Bounds, providing utilities for visibility checks, bounds calculations, and geometric analysis.
public static class ColliderExtensions
Inheritance
Methods
GetAttachedGameObject(Collider)
Returns the GameObject associated with this collider. If the collider has an attached Rigidbody, its GameObject is returned; otherwise, the collider's own GameObject is returned.
public static GameObject GetAttachedGameObject(this Collider collider)
Parameters
| Name | Type | Description |
|---|---|---|
collider | Collider | The collider to get the GameObject from. |
Returns
GameObject — The attached GameObject.
GetBounds(Collider[])
Calculates a bounding box encapsulating the combined bounds of the provided colliders.
public static Bounds GetBounds(this Collider[] colliders)
Parameters
| Name | Type | Description |
|---|---|---|
colliders | Collider[] | An array of colliders to encapsulate. |
Returns
Bounds — A Bounds object representing the combined volume of the colliders, or an empty Bounds if the array is empty.
GetBounds(Renderer[], Transform)
Calculates a bounding box that encapsulates the combined bounds of multiple renderers, transformed into the space of the specified origin transform.
public static Bounds GetBounds(this Renderer[] renderers, Transform origin)
Parameters
| Name | Type | Description |
|---|---|---|
renderers | Renderer[] | An array of renderers to calculate the bounds for. |
origin | Transform | The transform to calculate bounds relative to. |
Returns
Bounds — A Bounds object representing the combined bounds of all renderers, or an empty Bounds if none are valid.
GetLines(Bounds)
Returns the twelve edges (lines) that form the wireframe of the given Bounds as pairs of points.
public static Vector3[,] GetLines(this Bounds bounds)
Parameters
| Name | Type | Description |
|---|---|---|
bounds | Bounds | The bounds to extract edge lines from. |
Returns
Vector3[,] — A two-dimensional array where each row is a pair of Vector3 points representing one edge of the bounds.
GetPoints(Bounds)
Returns the eight corner points of the given Bounds.
public static Vector3[] GetPoints(this Bounds bounds)
Parameters
| Name | Type | Description |
|---|---|---|
bounds | Bounds | The bounds to extract points from. |
Returns
Vector3[] — An array of eight Vector3 points representing the corners of the bounds.
IsVisibleToCamera(Collider, Camera)
Checks if the collider is visible to the given camera by testing the collider's bounds against the camera's frustum.
public static bool IsVisibleToCamera(this Collider collider, Camera camera)
Parameters
| Name | Type | Description |
|---|---|---|
collider | Collider | The collider to check. |
camera | Camera | The camera to test against. |
Returns
bool — True if the collider is within the camera's view frustum; otherwise, false.
IsVisibleToCamera(Collider, Plane[])
Checks if the collider is visible to a custom frustum represented by an array of planes.
public static bool IsVisibleToCamera(this Collider collider, Plane[] cameraFrustum)
Parameters
| Name | Type | Description |
|---|---|---|
collider | Collider | The collider to check. |
cameraFrustum | Plane[] | The frustum planes to test against. |
Returns
bool — True if the collider is within the frustum; otherwise, false.