AnimationPlayableAssetUpgrade.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. namespace UnityEngine.Timeline
  3. {
  4. partial class AnimationPlayableAsset : ISerializationCallbackReceiver
  5. {
  6. enum Versions
  7. {
  8. Initial = 0,
  9. RotationAsEuler = 1,
  10. }
  11. static readonly int k_LatestVersion = (int)Versions.RotationAsEuler;
  12. [SerializeField, HideInInspector] int m_Version;
  13. [SerializeField, Obsolete("Use m_RotationEuler Instead", false), HideInInspector]
  14. private Quaternion m_Rotation = Quaternion.identity; // deprecated. now saves in euler angles
  15. void ISerializationCallbackReceiver.OnBeforeSerialize()
  16. {
  17. m_Version = k_LatestVersion;
  18. }
  19. void ISerializationCallbackReceiver.OnAfterDeserialize()
  20. {
  21. if (m_Version < k_LatestVersion)
  22. {
  23. OnUpgradeFromVersion(m_Version); //upgrade derived classes
  24. }
  25. }
  26. void OnUpgradeFromVersion(int oldVersion)
  27. {
  28. if (oldVersion < (int)Versions.RotationAsEuler)
  29. AnimationPlayableAssetUpgrade.ConvertRotationToEuler(this);
  30. }
  31. static class AnimationPlayableAssetUpgrade
  32. {
  33. public static void ConvertRotationToEuler(AnimationPlayableAsset asset)
  34. {
  35. #pragma warning disable 618
  36. asset.m_EulerAngles = asset.m_Rotation.eulerAngles;
  37. #pragma warning restore 618
  38. }
  39. }
  40. }
  41. }