BuiltInCurvePresets.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using UnityEngine;
  2. namespace UnityEditor.Timeline
  3. {
  4. // Preset libraries
  5. static class BuiltInPresets
  6. {
  7. static CurvePresetLibrary s_BlendInPresets;
  8. static CurvePresetLibrary s_BlendOutPresets;
  9. internal static CurvePresetLibrary blendInPresets
  10. {
  11. get
  12. {
  13. if (s_BlendInPresets == null)
  14. {
  15. s_BlendInPresets = ScriptableObject.CreateInstance<CurvePresetLibrary>();
  16. s_BlendInPresets.Add(new AnimationCurve(CurveEditorWindow.GetConstantKeys(1f)), "None");
  17. s_BlendInPresets.Add(new AnimationCurve(CurveEditorWindow.GetLinearKeys()), "Linear");
  18. s_BlendInPresets.Add(new AnimationCurve(CurveEditorWindow.GetEaseInKeys()), "EaseIn");
  19. s_BlendInPresets.Add(new AnimationCurve(CurveEditorWindow.GetEaseOutKeys()), "EaseOut");
  20. s_BlendInPresets.Add(new AnimationCurve(CurveEditorWindow.GetEaseInOutKeys()), "EaseInOut");
  21. }
  22. return s_BlendInPresets;
  23. }
  24. }
  25. internal static CurvePresetLibrary blendOutPresets
  26. {
  27. get
  28. {
  29. if (s_BlendOutPresets == null)
  30. {
  31. s_BlendOutPresets = ScriptableObject.CreateInstance<CurvePresetLibrary>();
  32. s_BlendOutPresets.Add(new AnimationCurve(CurveEditorWindow.GetConstantKeys(1f)), "None");
  33. s_BlendOutPresets.Add(ReverseCurve(new AnimationCurve(CurveEditorWindow.GetLinearKeys())), "Linear");
  34. s_BlendOutPresets.Add(ReverseCurve(new AnimationCurve(CurveEditorWindow.GetEaseInKeys())), "EaseIn");
  35. s_BlendOutPresets.Add(ReverseCurve(new AnimationCurve(CurveEditorWindow.GetEaseOutKeys())), "EaseOut");
  36. s_BlendOutPresets.Add(ReverseCurve(new AnimationCurve(CurveEditorWindow.GetEaseInOutKeys())), "EaseInOut");
  37. }
  38. return s_BlendOutPresets;
  39. }
  40. }
  41. static AnimationCurve ReverseCurve(AnimationCurve curve)
  42. {
  43. Keyframe[] keys = curve.keys;
  44. for (int i = 0; i < keys.Length; i++)
  45. {
  46. keys[i].value = 1 - keys[i].value;
  47. keys[i].inTangent *= -1;
  48. keys[i].outTangent *= -1;
  49. }
  50. curve.keys = keys;
  51. return curve;
  52. }
  53. }
  54. }