public static TimelineAsset GetCurrentActiveTimeline() { var timeline_win = TimelineUtils.GetTimelineWindow(); var asset = timeline_win.GetType().GetProperty("timeline"); var timeline = asset.GetValue(timeline_win, null) as TimelineAsset; return(timeline); }
public static void ToggleLockWindow() { var window = TimelineUtils.GetTimelineWindow(); PropertyInfo propertyInfo = window.GetType().GetProperty("locked"); bool value = (bool)propertyInfo.GetValue(window, null); propertyInfo.SetValue(window, !value, null); window.Repaint(); }
public static void SetTimeline(TimelineAsset timeline, PlayableDirector director) { var window = TimelineUtils.GetTimelineWindow(); #if UNITY_2018_2_OR_NEWER var method = window.GetType().GetMethod("SetCurrentTimeline", new[] { typeof(PlayableDirector), typeof(TimelineClip) }); var retVal = method.Invoke(window, new object[] { director, null }); #else var method = window.GetType().GetMethod("SetCurrentTimeline", new [] { typeof(TimelineAsset), typeof(PlayableDirector) }); method.Invoke(window, new object[] { timeline, director }); #endif Verify(retVal); }
public static void AlignClipsToTail(UnityEngine.Object[] objects) { Undo.RecordObjects(objects, "Align Clips to Tail"); List <double> startTimeList = new List <double>(); List <TimelineClip> clipList = new List <TimelineClip>(); foreach (var obj in objects) { var selectedClip = TimelineUtils.GetClip(obj); clipList.Add(selectedClip); startTimeList.Add(selectedClip.end); } double highest = startTimeList.Max(); foreach (var clip in clipList) { clip.start = highest - clip.duration; } TimelineUtils.GetTimelineWindow().Repaint(); }
public static void AlignClipsToHead(UnityEngine.Object[] objects) { Undo.RecordObjects(objects, "Align Clips to Head"); List <double> startTimeList = new List <double>(); List <TimelineClip> clipList = new List <TimelineClip>(); foreach (var obj in objects) { var selectedClip = TimelineUtils.GetClip(obj); clipList.Add(selectedClip); startTimeList.Add(selectedClip.start); } double lowest = startTimeList.Min(); foreach (var clip in clipList) { clip.start = lowest; } TimelineUtils.GetTimelineWindow().Repaint(); }
public static void SnapToNext(UnityEngine.Object[] objects) { Undo.RecordObjects(objects, "Snap To Next's Start"); List <TimelineClip> selectedClips = new List <TimelineClip>(); for (int i = 0; i < objects.Length; i++) { var selectedClip = TimelineUtils.GetClip(objects[i]); selectedClips.Add(selectedClip); } selectedClips = selectedClips.OrderBy(c => c.start).ToList(); selectedClips.Reverse(); for (int i = 0; i < selectedClips.Count; i++) { var selectedClip = selectedClips[i]; var selectedTrack = GetTrackBasedOnClip(selectedClip); var clipsInTrack = (Array)selectedTrack.GetClips(); var index = Array.IndexOf(clipsInTrack, selectedClip); // if found if (index > -1) { // and not the last clip in track if (index != clipsInTrack.Length - 1) { var nextClip = clipsInTrack.GetValue(index + 1) as TimelineClip; selectedClip.start = nextClip.start - selectedClip.duration; } } else { UnityEngine.Debug.LogWarning("Clip not found"); } } TimelineUtils.GetTimelineWindow().Repaint(); }