TimelineWindow_ActiveTimeline.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using UnityEngine;
  2. using UnityEngine.Playables;
  3. using UnityEngine.Timeline;
  4. namespace UnityEditor.Timeline
  5. {
  6. partial class TimelineWindow
  7. {
  8. private TimelineAsset m_PreviousMasterSequence;
  9. public void ClearCurrentTimeline()
  10. {
  11. SetCurrentTimeline(null, null, null, true);
  12. }
  13. public void SetCurrentTimeline(TimelineAsset seq)
  14. {
  15. SetCurrentTimeline(seq, null, null);
  16. }
  17. public void SetCurrentTimeline(PlayableDirector director, TimelineClip hostClip = null)
  18. {
  19. var asset = director != null ? director.playableAsset as TimelineAsset : null;
  20. SetCurrentTimeline(asset, director, hostClip);
  21. }
  22. void SetCurrentTimeline(TimelineAsset seq, PlayableDirector instanceOfDirector, TimelineClip hostClip, bool force = false)
  23. {
  24. if (state == null)
  25. return;
  26. if (!force &&
  27. state.editSequence.hostClip == hostClip &&
  28. state.editSequence.director == instanceOfDirector &&
  29. state.editSequence.asset == seq)
  30. return;
  31. state.SetCurrentSequence(seq, instanceOfDirector, hostClip);
  32. }
  33. void OnBeforeSequenceChange()
  34. {
  35. treeView = null;
  36. m_MarkerHeaderGUI = null;
  37. m_TimeAreaDirty = true;
  38. state.Reset();
  39. m_PlayableLookup.ClearPlayableLookup();
  40. // clear old editors to caches, like audio previews, get flushed
  41. CustomTimelineEditorCache.ClearCache<ClipEditor>();
  42. CustomTimelineEditorCache.ClearCache<MarkerEditor>();
  43. CustomTimelineEditorCache.ClearCache<TrackEditor>();
  44. m_PreviousMasterSequence = state.masterSequence.asset;
  45. }
  46. void OnAfterSequenceChange()
  47. {
  48. Repaint();
  49. m_SequencePath = state.GetCurrentSequencePath();
  50. m_LastFrameHadSequence = state.editSequence.asset != null;
  51. TimelineWindowViewPrefs.SaveAll();
  52. // this prevent clearing the animation window when going in/out of playmode, but
  53. // clears it when we switch master timelines
  54. // the cast to a object will handle the case where the sequence has been deleted.
  55. object previousMasterSequence = m_PreviousMasterSequence;
  56. bool isDeleted = previousMasterSequence != null && m_PreviousMasterSequence == null;
  57. bool hasChanged = m_PreviousMasterSequence != null && m_PreviousMasterSequence != state.masterSequence.asset;
  58. if (isDeleted || hasChanged)
  59. {
  60. AnimationClipCurveCache.Instance.Clear();
  61. TimelineAnimationUtilities.UnlinkAnimationWindow();
  62. }
  63. }
  64. }
  65. }