public static void GetItemRange(this TrackAsset track, out double start, out double end) { start = 0; end = 0; var items = track.GetItems().ToList(); if (items.Any()) { start = items.First().start; end = items.Last().end; } }
public static void GetItemRange(this TrackAsset track, out double start, out double end) { start = 0; end = 0; var items = track.GetItems().ToList(); if (items.Any()) { start = items.Min(p => p.start); end = items.Max(p => p.end); } }
static ITimelineItem GetClosestItem(TrackAsset track, ITimelineItem refItem) { var start = refItem.start; var end = refItem.end; var items = track.GetItems().ToList(); if (refItem is ClipItem) { items = items.Where(x => x is ClipItem).ToList(); } else { items = items.Where(x => x is MarkerItem).ToList(); } if (!items.Any()) { return(null); } ITimelineItem ret = null; var scoreToBeat = double.NegativeInfinity; foreach (var item in items) { // test for overlap var low = Math.Max(item.start, start); var high = Math.Min(item.end, end); if (low <= high) { var score = high - low; if (score >= scoreToBeat) { scoreToBeat = score; ret = item; } } } return(ret); }
public void Grab(IEnumerable <ITimelineItem> items, TrackAsset referenceTrack, Vector2 mousePosition) { if (items == null) { return; } items = items.ToArray(); // Cache enumeration result if (!items.Any()) { return; } m_GrabbedModalUndoGroup = Undo.GetCurrentGroup(); var trackItems = items.GroupBy(c => c.parentTrack).ToArray(); var trackItemsCount = trackItems.Length; movingItems = new MovingItems[trackItemsCount]; allowTrackSwitch = trackItemsCount == 1 && !trackItems.SelectMany(x => x).Any(x => x is MarkerItem); // For now, track switch is only supported when all items are on the same track and there are no items foreach (var item in referenceTrack.GetItems()) // Ripple changes other items { item.PushUndo("Move Items"); } for (var i = 0; i < trackItemsCount; ++i) { var track = trackItems[i].Key; var grabbedItems = new MovingItems(m_State, track, trackItems[i].ToArray(), referenceTrack, mousePosition, allowTrackSwitch); movingItems[i] = grabbedItems; } m_LeftMostMovingItems = null; m_RightMostMovingItems = null; foreach (var grabbedTrackItems in movingItems) { if (m_LeftMostMovingItems == null || m_LeftMostMovingItems.start > grabbedTrackItems.start) { m_LeftMostMovingItems = grabbedTrackItems; } if (m_RightMostMovingItems == null || m_RightMostMovingItems.end < grabbedTrackItems.end) { m_RightMostMovingItems = grabbedTrackItems; } } m_ItemGUIs = new HashSet <TimelineItemGUI>(); m_ItemsGroup = new ItemsGroup(items); foreach (var item in items) { m_ItemGUIs.Add(item.gui); } targetTrack = referenceTrack; EditMode.BeginMove(this); m_Grabbing = true; }