blob: 555f2051f68d788b75a58662c5370829a7dda26b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
using System;
using System.Collections;
using UnityEngine;
namespace UnitySA.Utility;
[Serializable]
public class FOVZoom
{
public Camera Camera;
[HideInInspector]
public float originalFov;
public float FOVIncrease = 3f;
public float TimeToIncrease = 1f;
public float TimeToDecrease = 1f;
public AnimationCurve IncreaseCurve;
public void Setup(Camera camera)
{
CheckStatus(camera);
Camera = camera;
originalFov = camera.fieldOfView;
}
private void CheckStatus(Camera camera)
{
if (camera == null)
{
throw new Exception("FOVKick camera is null, please supply the camera to the constructor");
}
if (IncreaseCurve == null)
{
throw new Exception("FOVKick Increase curve is null, please define the curve for the field of view kicks");
}
}
public void ChangeCamera(Camera camera)
{
Camera = camera;
}
public IEnumerator FOVKickUp()
{
float t = Mathf.Abs((Camera.fieldOfView - originalFov) / FOVIncrease);
while (t < TimeToIncrease)
{
Camera.fieldOfView = originalFov + IncreaseCurve.Evaluate(t / TimeToIncrease) * FOVIncrease;
t += Time.deltaTime;
yield return new WaitForEndOfFrame();
}
}
public IEnumerator FOVKickDown()
{
float t = Mathf.Abs((Camera.fieldOfView - originalFov) / FOVIncrease);
while (t > 0f)
{
Camera.fieldOfView = originalFov + IncreaseCurve.Evaluate(t / TimeToDecrease) * FOVIncrease;
t -= Time.deltaTime;
yield return new WaitForEndOfFrame();
}
Camera.fieldOfView = originalFov;
}
}
|