MoveItemModeMix.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using UnityEngine;
  4. using UnityEngine.Timeline;
  5. namespace UnityEditor.Timeline
  6. {
  7. class MoveItemModeMix : IMoveItemMode, IMoveItemDrawer
  8. {
  9. public void OnTrackDetach(IEnumerable<ItemsPerTrack> itemsGroups)
  10. {
  11. // Nothing
  12. }
  13. public void HandleTrackSwitch(IEnumerable<ItemsPerTrack> itemsGroups)
  14. {
  15. foreach (var itemsGroup in itemsGroups)
  16. {
  17. var targetTrack = itemsGroup.targetTrack;
  18. if (targetTrack != null && itemsGroup.items.Any())
  19. {
  20. var compatible = itemsGroup.items.First().IsCompatibleWithTrack(targetTrack) &&
  21. !EditModeUtils.IsInfiniteTrack(targetTrack);
  22. var track = compatible ? targetTrack : null;
  23. if (track != null)
  24. TimelineUndo.PushUndo(track, "Move Items");
  25. EditModeUtils.SetParentTrack(itemsGroup.items, track);
  26. }
  27. else
  28. {
  29. EditModeUtils.SetParentTrack(itemsGroup.items, null);
  30. }
  31. }
  32. }
  33. public bool AllowTrackSwitch()
  34. {
  35. return true;
  36. }
  37. public double AdjustStartTime(WindowState state, ItemsPerTrack itemsGroup, double time)
  38. {
  39. return time;
  40. }
  41. public void OnModeClutchEnter(IEnumerable<ItemsPerTrack> itemsGroups)
  42. {
  43. // Nothing
  44. }
  45. public void OnModeClutchExit(IEnumerable<ItemsPerTrack> itemsGroups)
  46. {
  47. // Nothing
  48. }
  49. public void BeginMove(IEnumerable<ItemsPerTrack> itemsGroups)
  50. {
  51. // Nothing
  52. }
  53. public void UpdateMove(IEnumerable<ItemsPerTrack> itemsGroups)
  54. {
  55. // Nothing
  56. }
  57. public void FinishMove(IEnumerable<ItemsPerTrack> itemsGroups)
  58. {
  59. // Nothing
  60. }
  61. public bool ValidateMove(ItemsPerTrack itemsGroup)
  62. {
  63. var track = itemsGroup.targetTrack;
  64. var items = itemsGroup.items;
  65. if (EditModeUtils.IsInfiniteTrack(track))
  66. {
  67. double startTime;
  68. double stopTime;
  69. EditModeUtils.GetInfiniteClipBoundaries(track, out startTime, out stopTime);
  70. return items.All(item =>
  71. !EditModeUtils.IsItemWithinRange(item, startTime, stopTime) &&
  72. !EditModeUtils.IsRangeWithinItem(startTime, stopTime, item));
  73. }
  74. var siblings = ItemsUtils.GetItemsExcept(itemsGroup.targetTrack, items);
  75. return items.All(item => EditModeMixUtils.GetPlacementValidity(item, siblings) == PlacementValidity.Valid);
  76. }
  77. public void DrawGUI(WindowState state, IEnumerable<MovingItems> movingItems, Color color)
  78. {
  79. var selectionHasAnyBlendIn = false;
  80. var selectionHasAnyBlendOut = false;
  81. foreach (var grabbedItems in movingItems)
  82. {
  83. var bounds = grabbedItems.onTrackItemsBounds;
  84. var counter = 0;
  85. foreach (var item in grabbedItems.items.OfType<IBlendable>())
  86. {
  87. if (item.hasLeftBlend)
  88. {
  89. EditModeGUIUtils.DrawBoundsEdge(bounds[counter], color, TrimEdge.Start);
  90. selectionHasAnyBlendIn = true;
  91. }
  92. if (item.hasRightBlend)
  93. {
  94. EditModeGUIUtils.DrawBoundsEdge(bounds[counter], color, TrimEdge.End);
  95. selectionHasAnyBlendOut = true;
  96. }
  97. counter++;
  98. }
  99. }
  100. if (selectionHasAnyBlendIn && selectionHasAnyBlendOut)
  101. {
  102. TimelineCursors.SetCursor(TimelineCursors.CursorType.MixBoth);
  103. }
  104. else if (selectionHasAnyBlendIn)
  105. {
  106. TimelineCursors.SetCursor(TimelineCursors.CursorType.MixLeft);
  107. }
  108. else if (selectionHasAnyBlendOut)
  109. {
  110. TimelineCursors.SetCursor(TimelineCursors.CursorType.MixRight);
  111. }
  112. else
  113. {
  114. TimelineCursors.ClearCursor();
  115. }
  116. }
  117. }
  118. }