ItemsGroup.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using UnityEngine;
  4. namespace UnityEditor.Timeline
  5. {
  6. class ItemsGroup
  7. {
  8. readonly ITimelineItem[] m_Items;
  9. readonly ITimelineItem m_LeftMostItem;
  10. readonly ITimelineItem m_RightMostItem;
  11. public ITimelineItem[] items
  12. {
  13. get { return m_Items; }
  14. }
  15. public double start
  16. {
  17. get { return m_LeftMostItem.start; }
  18. set
  19. {
  20. var offset = value - m_LeftMostItem.start;
  21. foreach (var clip in m_Items)
  22. clip.start += offset;
  23. }
  24. }
  25. public double end
  26. {
  27. get { return m_RightMostItem.end; }
  28. }
  29. public ITimelineItem leftMostItem
  30. {
  31. get { return m_LeftMostItem; }
  32. }
  33. public ITimelineItem rightMostItem
  34. {
  35. get { return m_RightMostItem; }
  36. }
  37. public ItemsGroup(IEnumerable<ITimelineItem> items)
  38. {
  39. Debug.Assert(items != null && items.Any());
  40. m_Items = items.ToArray();
  41. m_LeftMostItem = null;
  42. m_RightMostItem = null;
  43. foreach (var item in m_Items)
  44. {
  45. if (m_LeftMostItem == null || item.start < m_LeftMostItem.start)
  46. m_LeftMostItem = item;
  47. if (m_RightMostItem == null || item.end > m_RightMostItem.end)
  48. m_RightMostItem = item;
  49. }
  50. }
  51. }
  52. }