AnimationTrackUpgrade.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.ComponentModel;
  3. namespace UnityEngine.Timeline
  4. {
  5. partial class AnimationTrack
  6. {
  7. // 649 is value is only assigned to. they can be updated from old files being serialized
  8. #pragma warning disable 649
  9. //fields that are used for upgrading should be put here, ideally as read-only
  10. [SerializeField, Obsolete("Use m_InfiniteClipOffsetEulerAngles Instead", false), HideInInspector]
  11. Quaternion m_OpenClipOffsetRotation = Quaternion.identity;
  12. [SerializeField, Obsolete("Use m_RotationEuler Instead", false), HideInInspector]
  13. Quaternion m_Rotation = Quaternion.identity;
  14. [SerializeField, Obsolete("Use m_RootTransformOffsetMode", false), HideInInspector]
  15. bool m_ApplyOffsets;
  16. #pragma warning restore 649
  17. [EditorBrowsable(EditorBrowsableState.Never)]
  18. [Obsolete("openClipOffsetPosition has been deprecated. Use infiniteClipOffsetPosition instead. (UnityUpgradable) -> infiniteClipOffsetPosition", true)]
  19. public Vector3 openClipOffsetPosition
  20. {
  21. get { return infiniteClipOffsetPosition; }
  22. set { infiniteClipOffsetPosition = value; }
  23. }
  24. [EditorBrowsable(EditorBrowsableState.Never)]
  25. [Obsolete("openClipOffsetRotation has been deprecated. Use infiniteClipOffsetRotation instead. (UnityUpgradable) -> infiniteClipOffsetRotation", true)]
  26. public Quaternion openClipOffsetRotation
  27. {
  28. get { return infiniteClipOffsetRotation; }
  29. set { infiniteClipOffsetRotation = value; }
  30. }
  31. [EditorBrowsable(EditorBrowsableState.Never)]
  32. [Obsolete("openClipOffsetEulerAngles has been deprecated. Use infiniteClipOffsetEulerAngles instead. (UnityUpgradable) -> infiniteClipOffsetEulerAngles", true)]
  33. public Vector3 openClipOffsetEulerAngles
  34. {
  35. get { return infiniteClipOffsetEulerAngles; }
  36. set { infiniteClipOffsetEulerAngles = value; }
  37. }
  38. [EditorBrowsable(EditorBrowsableState.Never)]
  39. [Obsolete("openClipPreExtrapolation has been deprecated. Use infiniteClipPreExtrapolation instead. (UnityUpgradable) -> infiniteClipPreExtrapolation", true)]
  40. public TimelineClip.ClipExtrapolation openClipPreExtrapolation
  41. {
  42. get { return infiniteClipPreExtrapolation; }
  43. set { infiniteClipPreExtrapolation = value; }
  44. }
  45. [EditorBrowsable(EditorBrowsableState.Never)]
  46. [Obsolete("openClipPostExtrapolation has been deprecated. Use infiniteClipPostExtrapolation instead. (UnityUpgradable) -> infiniteClipPostExtrapolation", true)]
  47. public TimelineClip.ClipExtrapolation openClipPostExtrapolation
  48. {
  49. get { return infiniteClipPostExtrapolation; }
  50. set { infiniteClipPostExtrapolation = value; }
  51. }
  52. internal override void OnUpgradeFromVersion(int oldVersion)
  53. {
  54. if (oldVersion < (int)Versions.RotationAsEuler)
  55. AnimationTrackUpgrade.ConvertRotationsToEuler(this);
  56. if (oldVersion < (int)Versions.RootMotionUpgrade)
  57. AnimationTrackUpgrade.ConvertRootMotion(this);
  58. if (oldVersion < (int)Versions.AnimatedTrackProperties)
  59. AnimationTrackUpgrade.ConvertInfiniteTrack(this);
  60. }
  61. // 612 is Property is Obsolete
  62. // 618 is Field is Obsolete
  63. #pragma warning disable 612, 618
  64. static class AnimationTrackUpgrade
  65. {
  66. public static void ConvertRotationsToEuler(AnimationTrack track)
  67. {
  68. track.m_EulerAngles = track.m_Rotation.eulerAngles;
  69. track.m_InfiniteClipOffsetEulerAngles = track.m_OpenClipOffsetRotation.eulerAngles;
  70. }
  71. public static void ConvertRootMotion(AnimationTrack track)
  72. {
  73. track.m_TrackOffset = TrackOffset.Auto; // loaded tracks should use legacy mode
  74. // reset offsets if not applied
  75. if (!track.m_ApplyOffsets)
  76. {
  77. track.m_Position = Vector3.zero;
  78. track.m_EulerAngles = Vector3.zero;
  79. }
  80. }
  81. public static void ConvertInfiniteTrack(AnimationTrack track)
  82. {
  83. track.m_InfiniteClip = track.m_AnimClip;
  84. track.m_AnimClip = null;
  85. }
  86. }
  87. #pragma warning restore 612, 618
  88. }
  89. }