TrackUpgrade.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using UnityEngine.Serialization;
  3. namespace UnityEngine.Timeline
  4. {
  5. partial class TrackAsset : ISerializationCallbackReceiver
  6. {
  7. internal enum Versions
  8. {
  9. Initial = 0,
  10. RotationAsEuler = 1,
  11. RootMotionUpgrade = 2,
  12. AnimatedTrackProperties = 3
  13. }
  14. const int k_LatestVersion = (int)Versions.AnimatedTrackProperties;
  15. [SerializeField, HideInInspector] int m_Version;
  16. [Obsolete("Please use m_InfiniteClip (on AnimationTrack) instead.", false)]
  17. [SerializeField, HideInInspector, FormerlySerializedAs("m_animClip")]
  18. internal AnimationClip m_AnimClip;
  19. protected virtual void OnBeforeTrackSerialize() {}
  20. protected virtual void OnAfterTrackDeserialize() {}
  21. internal virtual void OnUpgradeFromVersion(int oldVersion) {}
  22. void ISerializationCallbackReceiver.OnBeforeSerialize()
  23. {
  24. m_Version = k_LatestVersion;
  25. //make sure children are correctly parented
  26. if (m_Children != null)
  27. {
  28. for (var i = m_Children.Count - 1; i >= 0; i--)
  29. {
  30. var asset = m_Children[i] as TrackAsset;
  31. if (asset != null && asset.parent != this)
  32. asset.parent = this;
  33. }
  34. }
  35. OnBeforeTrackSerialize();
  36. }
  37. void ISerializationCallbackReceiver.OnAfterDeserialize()
  38. {
  39. // Clear the clip cache when a deserialize is performed, or
  40. // we can get out of sync when performing Undo
  41. m_ClipsCache = null;
  42. Invalidate();
  43. if (m_Version < k_LatestVersion)
  44. {
  45. UpgradeToLatestVersion(); //upgrade TrackAsset
  46. OnUpgradeFromVersion(m_Version); //upgrade derived classes
  47. }
  48. foreach (var marker in GetMarkers())
  49. {
  50. marker.Initialize(this);
  51. }
  52. OnAfterTrackDeserialize();
  53. }
  54. //fields that are used for upgrading should be put here, ideally as read-only
  55. void UpgradeToLatestVersion()
  56. {}
  57. //upgrade code should go into this class
  58. static class TrackAssetUpgrade
  59. {}
  60. }
  61. }