IgnoreClipping.cs 897 B

123456789101112131415161718192021222324252627282930
  1. using UnityEngine;
  2. public class IgnoreClipping : MonoBehaviour
  3. {
  4. public int ignoreClippingLayer = 13;
  5. public float preClippingDistance = 500f;
  6. public int smallObjectsLayer = 14;
  7. public float smallObjectsDistance = 200f;
  8. private Camera cam;
  9. private void OnEnable()
  10. {
  11. cam = GetComponent<Camera>();
  12. applyDistances();
  13. }
  14. public void applyDistances(float? overridePreClippingDistance = null, float? overrideSmallObjectsDistance = null)
  15. {
  16. var pcD = overridePreClippingDistance ?? preClippingDistance;
  17. var soD = overrideSmallObjectsDistance ?? smallObjectsDistance;
  18. var distances = new float[32];
  19. for (var i = 0; i < distances.Length; i++) distances[i] = pcD;
  20. distances[ignoreClippingLayer] = 0f;
  21. distances[smallObjectsLayer] = soD;
  22. cam.layerCullDistances = distances;
  23. }
  24. }