CameraPotentialVisibleObjectsSphere.cs 922 B

123456789101112131415161718192021222324252627282930
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. namespace O3DWB
  4. {
  5. public class CameraPotentialVisibleObjectsSphere
  6. {
  7. #region Private Variables
  8. private float _radius;
  9. private Vector3 _center;
  10. #endregion
  11. #region Public Properties
  12. public float Radius { get { return _radius; } }
  13. public Vector3 Center { get { return _center; } }
  14. public Sphere Sphere { get { return new Sphere(_center, _radius); } }
  15. #endregion
  16. #region Public Methods
  17. public void Calculate(Camera camera, CameraViewVolume cameraViewVolume)
  18. {
  19. Transform cameraTransform = camera.transform;
  20. _center = cameraTransform.position + cameraTransform.forward * cameraViewVolume.FarClipPlaneDistance * 0.5f;
  21. _radius = (cameraViewVolume.TopLeftPointOnFarPlane - _center).magnitude * 1.01f;
  22. }
  23. #endregion
  24. }
  25. }
  26. #endif