MoveItemModeReplace.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace UnityEditor.Timeline
  4. {
  5. class MoveItemModeReplace : IMoveItemMode, IMoveItemDrawer
  6. {
  7. public void OnTrackDetach(IEnumerable<ItemsPerTrack> itemsGroups)
  8. {
  9. // Nothing
  10. }
  11. public void HandleTrackSwitch(IEnumerable<ItemsPerTrack> itemsGroups)
  12. {
  13. // Nothing
  14. }
  15. public bool AllowTrackSwitch()
  16. {
  17. return true;
  18. }
  19. public double AdjustStartTime(WindowState state, ItemsPerTrack itemsGroup, double time)
  20. {
  21. return time;
  22. }
  23. public void OnModeClutchEnter(IEnumerable<ItemsPerTrack> itemsGroups)
  24. {
  25. // TODO
  26. }
  27. public void OnModeClutchExit(IEnumerable<ItemsPerTrack> itemsGroups)
  28. {
  29. // TODO
  30. }
  31. public void BeginMove(IEnumerable<ItemsPerTrack> itemsGroups)
  32. {
  33. foreach (var itemsGroup in itemsGroups)
  34. {
  35. EditModeUtils.SetParentTrack(itemsGroup.items, null);
  36. }
  37. }
  38. public void UpdateMove(IEnumerable<ItemsPerTrack> itemsGroups)
  39. {
  40. // Nothing
  41. }
  42. public void FinishMove(IEnumerable<ItemsPerTrack> itemsGroups)
  43. {
  44. EditModeReplaceUtils.Insert(itemsGroups);
  45. }
  46. public bool ValidateMove(ItemsPerTrack itemsGroup)
  47. {
  48. return true;
  49. }
  50. public void DrawGUI(WindowState state, IEnumerable<MovingItems> movingItems, Color color)
  51. {
  52. var operationWillReplace = false;
  53. foreach (var itemsPerTrack in movingItems)
  54. {
  55. var bounds = itemsPerTrack.onTrackItemsBounds;
  56. var counter = 0;
  57. foreach (var item in itemsPerTrack.items)
  58. {
  59. if (EditModeUtils.GetFirstIntersectedItem(itemsPerTrack.items, item.start) != null)
  60. {
  61. EditModeGUIUtils.DrawBoundsEdge(bounds[counter], color, TrimEdge.Start);
  62. operationWillReplace = true;
  63. }
  64. if (EditModeUtils.GetFirstIntersectedItem(itemsPerTrack.items, item.end) != null)
  65. {
  66. EditModeGUIUtils.DrawBoundsEdge(bounds[counter], color, TrimEdge.End);
  67. operationWillReplace = true;
  68. }
  69. counter++;
  70. // TODO Display swallowed clips?
  71. }
  72. }
  73. if (operationWillReplace)
  74. {
  75. TimelineCursors.SetCursor(TimelineCursors.CursorType.Replace);
  76. }
  77. else
  78. {
  79. TimelineCursors.ClearCursor();
  80. }
  81. }
  82. }
  83. }