ColorGradingCurve.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. namespace UnityEngine.PostProcessing
  3. {
  4. [Serializable]
  5. public sealed class ColorGradingCurve
  6. {
  7. public ColorGradingCurve(AnimationCurve curve, float zeroValue, bool loop, Vector2 bounds)
  8. {
  9. this.curve = curve;
  10. this.m_ZeroValue = zeroValue;
  11. this.m_Loop = loop;
  12. this.m_Range = bounds.magnitude;
  13. }
  14. public void Cache()
  15. {
  16. if (!this.m_Loop)
  17. {
  18. return;
  19. }
  20. int length = this.curve.length;
  21. if (length < 2)
  22. {
  23. return;
  24. }
  25. if (this.m_InternalLoopingCurve == null)
  26. {
  27. this.m_InternalLoopingCurve = new AnimationCurve();
  28. }
  29. Keyframe key = this.curve[length - 1];
  30. key.time -= this.m_Range;
  31. Keyframe key2 = this.curve[0];
  32. key2.time += this.m_Range;
  33. this.m_InternalLoopingCurve.keys = this.curve.keys;
  34. this.m_InternalLoopingCurve.AddKey(key);
  35. this.m_InternalLoopingCurve.AddKey(key2);
  36. }
  37. public float Evaluate(float t)
  38. {
  39. if (this.curve.length == 0)
  40. {
  41. return this.m_ZeroValue;
  42. }
  43. if (!this.m_Loop || this.curve.length == 1)
  44. {
  45. return this.curve.Evaluate(t);
  46. }
  47. return this.m_InternalLoopingCurve.Evaluate(t);
  48. }
  49. public AnimationCurve curve;
  50. [SerializeField]
  51. private bool m_Loop;
  52. [SerializeField]
  53. private float m_ZeroValue;
  54. [SerializeField]
  55. private float m_Range;
  56. private AnimationCurve m_InternalLoopingCurve;
  57. }
  58. }