diff options
author | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
commit | 6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch) | |
tree | b38119d2acf0a982cb67e381f146924b9bfc3b3f /UnityEngine.PostProcessing/ColorGradingCurve.cs |
+init
Diffstat (limited to 'UnityEngine.PostProcessing/ColorGradingCurve.cs')
-rw-r--r-- | UnityEngine.PostProcessing/ColorGradingCurve.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/UnityEngine.PostProcessing/ColorGradingCurve.cs b/UnityEngine.PostProcessing/ColorGradingCurve.cs new file mode 100644 index 0000000..49ea13a --- /dev/null +++ b/UnityEngine.PostProcessing/ColorGradingCurve.cs @@ -0,0 +1,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); + } +} |