From c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 19 Apr 2020 17:19:32 -0400 Subject: Inital commit --- .../Editor/Items/ItemsUtils.cs | 116 +++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 Library/PackageCache/com.unity.timeline@1.2.13/Editor/Items/ItemsUtils.cs (limited to 'Library/PackageCache/com.unity.timeline@1.2.13/Editor/Items/ItemsUtils.cs') diff --git a/Library/PackageCache/com.unity.timeline@1.2.13/Editor/Items/ItemsUtils.cs b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/Items/ItemsUtils.cs new file mode 100644 index 0000000..90e7985 --- /dev/null +++ b/Library/PackageCache/com.unity.timeline@1.2.13/Editor/Items/ItemsUtils.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine.Timeline; + +namespace UnityEditor.Timeline +{ + static class ItemsUtils + { + static readonly Dictionary s_ClipCache = new Dictionary(); + static readonly Dictionary s_MarkerCache = new Dictionary(); + + public static IEnumerable ToItemsPerTrack(this IEnumerable items) + { + var groupedItems = items.GroupBy(c => c.parentTrack); + foreach (var group in groupedItems) + { + yield return new ItemsPerTrack(group.Key, group.ToArray()); + } + } + + public static ITimelineItem ToItem(this TimelineClip clip) + { + if (s_ClipCache.ContainsKey(clip)) + return s_ClipCache[clip]; + + var ret = new ClipItem(clip); + s_ClipCache.Add(clip, ret); + return ret; + } + + public static ITimelineItem ToItem(this IMarker marker) + { + if (s_MarkerCache.ContainsKey(marker)) + return s_MarkerCache[marker]; + + var ret = new MarkerItem(marker); + s_MarkerCache.Add(marker, ret); + return ret; + } + + public static IEnumerable ToItems(this IEnumerable clips) + { + return clips.Select(ToItem); + } + + public static IEnumerable ToItems(this IEnumerable markers) + { + return markers.Select(ToItem); + } + + public static IEnumerable GetItems(this TrackAsset track) + { + var list = track.clips.Select(clip => (ITimelineItem) new ClipItem(clip)).ToList(); + list.AddRange(track.GetMarkers().Select(marker => (ITimelineItem) new MarkerItem(marker))); + + list = list.OrderBy(x => x.start).ThenBy(x => x.end).ToList(); + return list; + } + + 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); + } + } + + public static IEnumerable GetItemsExcept(this TrackAsset track, IEnumerable items) + { + return GetItems(track).Except(items); + } + + public static IEnumerable GetItemTypes(IEnumerable items) + { + var types = new List(); + if (items.OfType().Any()) + types.Add(typeof(ClipItem)); + if (items.OfType().Any()) + types.Add(typeof(MarkerItem)); + + return types; + } + + public static IEnumerable GetItemTypes(IEnumerable itemsGroups) + { + return GetItemTypes(itemsGroups.SelectMany(i => i.items)).Distinct(); + } + + public static void SetItemsStartTime(IEnumerable newItems, double time) + { + var startTimes = newItems.Select(d => d.items.Min(x => x.start)).ToList(); + var min = startTimes.Min(); + startTimes = startTimes.Select(x => x - min + time).ToList(); + + for (int i = 0; i < newItems.Count(); ++i) + EditModeUtils.SetStart(newItems.ElementAt(i).items, startTimes[i]); + } + + public static double TimeGapBetweenItems(ITimelineItem leftItem, ITimelineItem rightItem, WindowState state) + { + if (leftItem is MarkerItem && rightItem is MarkerItem) + { + var markerType = ((MarkerItem)leftItem).marker.GetType(); + var gap = state.PixelDeltaToDeltaTime(StyleManager.UssStyleForType(markerType).fixedWidth); + return gap; + } + + return 0.0; + } + } +} -- cgit v1.2.3