Skip to main content

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​

NameTypeDescription
cameraCameraThe camera to check against.
boundsBoundsThe 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​

NameTypeDescription
cameraFrustumPlane[]An array of planes representing a camera's view frustum.
boundsBoundsThe 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​

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

NameTypeDescription
cameraFrustumPlane[]An array of planes representing a camera's view frustum.
colliderColliderThe 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​

NameTypeDescription
cameraCameraThe camera to check against.
collidersCollider[]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​

NameTypeDescription
cameraFrustumPlane[]An array of planes representing a camera's view frustum.
collidersCollider[]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​

NameTypeDescription
camCameraThe target camera.
layerMaskintLayer 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​

NameTypeDescription
camCameraThe target camera.
layerstringThe 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​

NameTypeDescription
camCameraThe target camera.
layerMaskintLayer 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​

NameTypeDescription
camCameraThe target camera.
layerstringThe 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​

NameTypeDescription
camCameraThe target camera.
layerMaskintLayer 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​

NameTypeDescription
camCameraThe target camera.
layerstringThe 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​

NameTypeDescription
camCameraThe target camera.
layerMaskintLayer 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​

NameTypeDescription
camCameraThe target camera.
layerstringThe 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​

NameTypeDescription
camCameraThe target camera.
layerMaskintLayer mask representing the layers to toggle.
isOnboolTrue 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​

NameTypeDescription
camCameraThe target camera.
layerstringThe name of the layer to toggle.
isOnboolTrue to show the layer, false to hide it.
  • Methods
    • IsBoundsInSight(Camera, Bounds)
    • IsBoundsInSight(Plane[], Bounds)
    • IsColliderInSight(Camera, Collider)
    • IsColliderInSight(Plane[], Collider)
    • IsCollidersInSight(Camera, Collider[])
    • IsCollidersInSight(Plane[], Collider[])
    • LayerCullingHide(Camera, int)
    • LayerCullingHide(Camera, string)
    • LayerCullingIncludes(Camera, int)
    • LayerCullingIncludes(Camera, string)
    • LayerCullingShow(Camera, int)
    • LayerCullingShow(Camera, string)
    • LayerCullingToggle(Camera, int)
    • LayerCullingToggle(Camera, string)
    • LayerCullingToggle(Camera, int, bool)
    • LayerCullingToggle(Camera, string, bool)