Class CameraExtensions
Provides extension methods for the Unity Camera class to simplify layer culling control and frustum visibility checks for colliders and bounds.
public static class CameraExtensions
Inheritance
Methods
IsBoundsInSight(Camera, Bounds)
Determines whether the specified bounds are within the camera's view frustum.
public static bool IsBoundsInSight(this Camera camera, Bounds bounds)
Parameters
| Name | Type | Description |
|---|---|---|
camera | Camera | The camera to check against. |
bounds | Bounds | The bounds to test for visibility. |
Returns
bool — True if the bounds are within the camera's view; otherwise, false.
IsBoundsInSight(Plane[], Bounds)
Determines whether the specified bounds are within the provided frustum planes.
public static bool IsBoundsInSight(this Plane[] cameraFrustum, Bounds bounds)
Parameters
| Name | Type | Description |
|---|---|---|
cameraFrustum | Plane[] | An array of planes representing a camera's view frustum. |
bounds | Bounds | The bounds to test for visibility. |
Returns
bool — True if the bounds are within the frustum; otherwise, false.
IsColliderInSight(Camera, Collider)
Determines whether the specified collider is currently within the camera's view frustum.
public static bool IsColliderInSight(this Camera camera, Collider collider)
Parameters
| Name | Type | Description |
|---|---|---|
camera | Camera | The camera to check against. |
collider | Collider | The collider to test for visibility. |
Returns
bool — True if the collider is within the camera's view; otherwise, false.
IsColliderInSight(Plane[], Collider)
Determines whether the specified collider is within the provided frustum planes.
public static bool IsColliderInSight(this Plane[] cameraFrustum, Collider collider)
Parameters
| Name | Type | Description |
|---|---|---|
cameraFrustum | Plane[] | An array of planes representing a camera's view frustum. |
collider | Collider | The collider to test for visibility. |
Returns
bool — True if the collider is within the frustum; otherwise, false.
IsCollidersInSight(Camera, Collider[])
Determines whether any of the provided colliders are within the camera's view frustum.
public static bool IsCollidersInSight(this Camera camera, Collider[] colliders)
Parameters
| Name | Type | Description |
|---|---|---|
camera | Camera | The camera to check against. |
colliders | Collider[] | Array of colliders to test for visibility. |
Returns
bool — True if any collider is within the camera's view; otherwise, false.
IsCollidersInSight(Plane[], Collider[])
Determines whether any of the provided colliders are within the provided frustum planes.
public static bool IsCollidersInSight(this Plane[] cameraFrustum, Collider[] colliders)
Parameters
| Name | Type | Description |
|---|---|---|
cameraFrustum | Plane[] | An array of planes representing a camera's view frustum. |
colliders | Collider[] | Array of colliders to test for visibility. |
Returns
bool — True if any collider is within the frustum; otherwise, false.
LayerCullingHide(Camera, int)
Removes the specified layer mask from the camera's culling mask, hiding the layer.
public static void LayerCullingHide(this Camera cam, int layerMask)
Parameters
| Name | Type | Description |
|---|---|---|
cam | Camera | The target camera. |
layerMask | int | Layer mask representing the layers to hide. |
LayerCullingHide(Camera, string)
Removes the specified layer by name from the camera's culling mask, hiding the layer.
public static void LayerCullingHide(this Camera cam, string layer)
Parameters
| Name | Type | Description |
|---|---|---|
cam | Camera | The target camera. |
layer | string | The name of the layer to hide. |
LayerCullingIncludes(Camera, int)
Checks whether the specified layer mask is currently visible in the camera's culling mask.
public static bool LayerCullingIncludes(this Camera cam, int layerMask)
Parameters
| Name | Type | Description |
|---|---|---|
cam | Camera | The target camera. |
layerMask | int | Layer mask to check. |
Returns
bool — True if the layer is visible; otherwise, false.
LayerCullingIncludes(Camera, string)
Checks whether the specified layer by name is currently visible in the camera's culling mask.
public static bool LayerCullingIncludes(this Camera cam, string layer)
Parameters
| Name | Type | Description |
|---|---|---|
cam | Camera | The target camera. |
layer | string | The name of the layer to check. |
Returns
bool — True if the layer is visible; otherwise, false.
LayerCullingShow(Camera, int)
Adds the specified layer mask to the camera's culling mask, making the layer visible.
public static void LayerCullingShow(this Camera cam, int layerMask)
Parameters
| Name | Type | Description |
|---|---|---|
cam | Camera | The target camera. |
layerMask | int | Layer mask representing the layers to show. |
LayerCullingShow(Camera, string)
Adds the specified layer by name to the camera's culling mask, making the layer visible.
public static void LayerCullingShow(this Camera cam, string layer)
Parameters
| Name | Type | Description |
|---|---|---|
cam | Camera | The target camera. |
layer | string | The name of the layer to show. |
LayerCullingToggle(Camera, int)
Toggles the visibility of the specified layer mask in the camera's culling mask.
public static void LayerCullingToggle(this Camera cam, int layerMask)
Parameters
| Name | Type | Description |
|---|---|---|
cam | Camera | The target camera. |
layerMask | int | Layer mask representing the layers to toggle. |
LayerCullingToggle(Camera, string)
Toggles the visibility of the specified layer by name in the camera's culling mask.
public static void LayerCullingToggle(this Camera cam, string layer)
Parameters
| Name | Type | Description |
|---|---|---|
cam | Camera | The target camera. |
layer | string | The name of the layer to toggle. |
LayerCullingToggle(Camera, int, bool)
Sets the visibility of the specified layer mask in the camera's culling mask based on the provided boolean value.
public static void LayerCullingToggle(this Camera cam, int layerMask, bool isOn)
Parameters
| Name | Type | Description |
|---|---|---|
cam | Camera | The target camera. |
layerMask | int | Layer mask representing the layers to toggle. |
isOn | bool | True to show the layers, false to hide them. |
LayerCullingToggle(Camera, string, bool)
Sets the visibility of the specified layer by name in the camera's culling mask based on the provided boolean value.
public static void LayerCullingToggle(this Camera cam, string layer, bool isOn)
Parameters
| Name | Type | Description |
|---|---|---|
cam | Camera | The target camera. |
layer | string | The name of the layer to toggle. |
isOn | bool | True to show the layer, false to hide it. |