Skip to content

Instantly share code, notes, and snippets.

@TarasOsiris
Created November 26, 2014 13:51
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save TarasOsiris/a8904989c18424bcdf73 to your computer and use it in GitHub Desktop.
Save TarasOsiris/a8904989c18424bcdf73 to your computer and use it in GitHub Desktop.
using UnityEngine;
public static class CameraExtensions {
public static void LayerCullingShow(this Camera cam, int layerMask) {
cam.cullingMask |= layerMask;
}
public static void LayerCullingShow(this Camera cam, string layer) {
LayerCullingShow(cam, 1 << LayerMask.NameToLayer(layer));
}
public static void LayerCullingHide(this Camera cam, int layerMask) {
cam.cullingMask &= ~layerMask;
}
public static void LayerCullingHide(this Camera cam, string layer) {
LayerCullingHide(cam, 1 << LayerMask.NameToLayer(layer));
}
public static void LayerCullingToggle(this Camera cam, int layerMask) {
cam.cullingMask ^= layerMask;
}
public static void LayerCullingToggle(this Camera cam, string layer) {
LayerCullingToggle(cam, 1 << LayerMask.NameToLayer(layer));
}
public static bool LayerCullingIncludes(this Camera cam, int layerMask) {
return (cam.cullingMask & layerMask) > 0;
}
public static bool LayerCullingIncludes(this Camera cam, string layer) {
return LayerCullingIncludes(cam, 1 << LayerMask.NameToLayer(layer));
}
public static void LayerCullingToggle(this Camera cam, int layerMask, bool isOn) {
bool included = LayerCullingIncludes(cam, layerMask);
if (isOn && !included) {
LayerCullingShow(cam, layerMask);
} else if (!isOn && included) {
LayerCullingHide(cam, layerMask);
}
}
public static void LayerCullingToggle(this Camera cam, string layer, bool isOn) {
LayerCullingToggle(cam, 1 << LayerMask.NameToLayer(layer), isOn);
}
}
@Monsoonexe
Copy link

Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment