Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(Camera))]
  4. public class CameraGizmoDrawer : MonoBehaviour
  5. {
  6. Camera m_camera;
  7.  
  8. void OnDrawGizmos()
  9. {
  10. if (m_camera == null)
  11. {
  12. m_camera = gameObject.GetComponent<Camera>();
  13. }
  14.  
  15. Color tempColor = Gizmos.color;
  16. Matrix4x4 tempMat = Gizmos.matrix;
  17. if (this.m_camera.orthographic)
  18. {
  19. Camera c = m_camera;
  20. var size = c.orthographicSize;
  21. Gizmos.DrawWireCube(Vector3.forward * (c.nearClipPlane + (c.farClipPlane-c.nearClipPlane)/2)
  22. , new Vector3(size * 2.0f, size * 2.0f * c.aspect, c.farClipPlane-c.nearClipPlane));
  23. }
  24. else
  25. {
  26. Camera c = m_camera;
  27. Gizmos.matrix = Matrix4x4.TRS(this.transform.position, this.transform.rotation, Vector3.one);
  28. Gizmos.DrawFrustum(Vector3.zero, c.fieldOfView, c.farClipPlane, c.nearClipPlane, c.aspect);
  29. }
  30. Gizmos.color = tempColor;
  31. Gizmos.matrix = tempMat;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement