summaryrefslogtreecommitdiff
path: root/UnityEngine.PostProcessing/ColorGradingCurve.cs
blob: 49ea13a01493b5babc166b669d8a02dd075de562 (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
using System;

namespace UnityEngine.PostProcessing;

[Serializable]
public sealed class ColorGradingCurve
{
	public AnimationCurve curve;

	[SerializeField]
	private bool m_Loop;

	[SerializeField]
	private float m_ZeroValue;

	[SerializeField]
	private float m_Range;

	private AnimationCurve m_InternalLoopingCurve;

	public ColorGradingCurve(AnimationCurve curve, float zeroValue, bool loop, Vector2 bounds)
	{
		this.curve = curve;
		m_ZeroValue = zeroValue;
		m_Loop = loop;
		m_Range = bounds.magnitude;
	}

	public void Cache()
	{
		if (!m_Loop)
		{
			return;
		}
		int length = curve.length;
		if (length >= 2)
		{
			if (m_InternalLoopingCurve == null)
			{
				m_InternalLoopingCurve = new AnimationCurve();
			}
			Keyframe key = curve[length - 1];
			key.time -= m_Range;
			Keyframe key2 = curve[0];
			key2.time += m_Range;
			m_InternalLoopingCurve.keys = curve.keys;
			m_InternalLoopingCurve.AddKey(key);
			m_InternalLoopingCurve.AddKey(key2);
		}
	}

	public float Evaluate(float t)
	{
		if (curve.length == 0)
		{
			return m_ZeroValue;
		}
		if (!m_Loop || curve.length == 1)
		{
			return curve.Evaluate(t);
		}
		return m_InternalLoopingCurve.Evaluate(t);
	}
}