Skip to main content

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​

NameTypeDescription
colliderColliderThe 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​

NameTypeDescription
collidersCollider[]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​

NameTypeDescription
renderersRenderer[]An array of renderers to calculate the bounds for.
originTransformThe 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​

NameTypeDescription
boundsBoundsThe 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​

NameTypeDescription
boundsBoundsThe 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​

NameTypeDescription
colliderColliderThe collider to check.
cameraCameraThe 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​

NameTypeDescription
colliderColliderThe collider to check.
cameraFrustumPlane[]The frustum planes to test against.

Returns​

bool — True if the collider is within the frustum; otherwise, false.

  • Methods
    • GetAttachedGameObject(Collider)
    • GetBounds(Collider[])
    • GetBounds(Renderer[], Transform)
    • GetLines(Bounds)
    • GetPoints(Bounds)
    • IsVisibleToCamera(Collider, Camera)
    • IsVisibleToCamera(Collider, Plane[])