Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public static class CameraExtensions {
  4. public static void LayerCullingSetVisible(this Camera cam, int layerMask, bool visible) {
  5. if (visible) LayerCullingShow(cam, layerMask);
  6. else LayerCullingHide(cam, layerMask);
  7. }
  8.  
  9. public static void LayerCullingSetVisible(this Camera cam, string layer, bool visible) {
  10. if (visible) LayerCullingShow(cam, layer);
  11. else LayerCullingHide(cam, layer);
  12. }
  13.  
  14. public static void LayerCullingShow(this Camera cam, int layerMask) {
  15. cam.cullingMask |= layerMask;
  16. }
  17.  
  18. public static void LayerCullingShow(this Camera cam, string layer) {
  19. LayerCullingShow(cam, 1 << LayerMask.NameToLayer(layer));
  20. }
  21.  
  22. public static void LayerCullingHide(this Camera cam, int layerMask) {
  23. cam.cullingMask &= ~layerMask;
  24. }
  25.  
  26. public static void LayerCullingHide(this Camera cam, string layer) {
  27. LayerCullingHide(cam, 1 << LayerMask.NameToLayer(layer));
  28. }
  29.  
  30. public static void LayerCullingToggle(this Camera cam, int layerMask) {
  31. cam.cullingMask ^= layerMask;
  32. }
  33.  
  34. public static void LayerCullingToggle(this Camera cam, string layer) {
  35. LayerCullingToggle(cam, 1 << LayerMask.NameToLayer(layer));
  36. }
  37.  
  38. public static bool LayerCullingIncludes(this Camera cam, int layerMask) {
  39. return (cam.cullingMask & layerMask) > 0;
  40. }
  41.  
  42. public static bool LayerCullingIncludes(this Camera cam, string layer) {
  43. return LayerCullingIncludes(cam, 1 << LayerMask.NameToLayer(layer));
  44. }
  45.  
  46. public static void LayerCullingToggle(this Camera cam, int layerMask, bool isOn) {
  47. bool included = LayerCullingIncludes(cam, layerMask);
  48. if (isOn && !included) {
  49. LayerCullingShow(cam, layerMask);
  50. } else if (!isOn && included) {
  51. LayerCullingHide(cam, layerMask);
  52. }
  53. }
  54.  
  55. public static void LayerCullingToggle(this Camera cam, string layer, bool isOn) {
  56. LayerCullingToggle(cam, 1 << LayerMask.NameToLayer(layer), isOn);
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement