暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TimelineWindow_ActiveTimeline.cs 3.0KB

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