UnityEssentials
Small but useful tools and features for Unity
CameraExtensions.cs
Go to the documentation of this file.
1 namespace UnityEngine
2 {
6 
7  public static class CameraExtensions
8  {
13  public static void SetLerp(this Camera self, Camera a, Camera b, float t)
14  {
15  Color backgroundColor = Color.Lerp(a.backgroundColor,b.backgroundColor,t);
16  float fieldOfView = Mathf.Lerp(a.fieldOfView, b.fieldOfView, t);
17  float farClipPlane = Mathf.Lerp(a.farClipPlane, b.farClipPlane, t);
18  float nearClipPlane = Mathf.Lerp(a.nearClipPlane, b.nearClipPlane, t);
19  Rect rect = new Rect(Vector2.Lerp(a.rect.position, b.rect.position, t), Vector2.Lerp(a.rect.size, b.rect.size, t));
20  //Rect rect = self.rect;
21  float depth = Mathf.Lerp(a.depth, b.depth, t);
22 
23  self.SetProperties(backgroundColor, fieldOfView, farClipPlane, nearClipPlane, rect, depth);
24  }
25 
35  public static void SetProperties(this Camera cam, Color backgroundColor, float fieldOfView, float farClipPlane, float nearClipPlane, Rect rect, float depth)
36  {
37  cam.backgroundColor = backgroundColor;
38  cam.fieldOfView = fieldOfView;
39  cam.farClipPlane = farClipPlane;
40  cam.nearClipPlane = nearClipPlane;
41  cam.rect = rect;
42  cam.depth = depth;
43  }
44  }
45 }
46 
Extensions for the Camera component
static void SetLerp(this Camera self, Camera a, Camera b, float t)
Linearly interpolates between two cameras.
static void SetProperties(this Camera cam, Color backgroundColor, float fieldOfView, float farClipPlane, float nearClipPlane, Rect rect, float depth)
Sets the camera parameters that can be linearly interpolated.