static void FixLoops(TimelineClip clip, bool completeLastLoop) { if (!TimelineHelpers.HasUsableAssetDuration(clip)) { return; } var loopDuration = TimelineHelpers.GetLoopDuration(clip); var firstLoopDuration = loopDuration - clip.clipIn * (1.0 / clip.timeScale); // Making sure we don't trim to zero if (!completeLastLoop && firstLoopDuration > clip.duration) { return; } var numLoops = (clip.duration - firstLoopDuration) / loopDuration; var numCompletedLoops = Math.Floor(numLoops); if (!(numCompletedLoops < numLoops)) { return; } if (completeLastLoop) { numCompletedLoops += 1; } var newEnd = clip.start + firstLoopDuration + loopDuration * numCompletedLoops; TimelineUndo.PushUndo(clip.parentTrack, "Trim Clip Last Loop"); TrimClipWithEditMode(clip, TrimEdge.End, newEnd); }
public static bool MatchContent(TimelineClip clip) { if (clip.asset == null) { return(false); } TimelineUndo.PushUndo(clip.parentTrack, "Match Clip Content"); var newStartCandidate = clip.start - clip.clipIn / clip.timeScale; var newStart = newStartCandidate < 0.0 ? 0.0 : newStartCandidate; TrimClipWithEditMode(clip, TrimEdge.Start, newStart); // In case resetting the start was blocked by edit mode or timeline start, we do the best we can clip.clipIn = (clip.start - newStartCandidate) * clip.timeScale; if (TimelineHelpers.HasUsableAssetDuration(clip)) { var duration = TimelineHelpers.GetLoopDuration(clip); var offset = (clip.clipIn / clip.timeScale) % duration; TrimClipWithEditMode(clip, TrimEdge.End, clip.start - offset + duration); } return(true); }
public static double[] GetLoopTimes(TimelineClip clip) { double[] result; if (!TimelineHelpers.HasUsableAssetDuration(clip)) { result = new double[] { -clip.clipIn / clip.timeScale }; } else { List <double> list = new List <double>(); double loopDuration = TimelineHelpers.GetLoopDuration(clip); if (loopDuration <= TimeUtility.kTimeEpsilon) { result = new double[0]; } else { double num = -clip.clipIn / clip.timeScale; double num2 = num + loopDuration; list.Add(num); while (num2 < clip.duration - TimelineWindow.TimelineState.kTimeEpsilon) { list.Add(num2); num2 += loopDuration; } result = list.ToArray(); } } return(result); }
void CalculateLoopRects(Rect trackRect, WindowState state) { if (!m_ClipViewDirty) { return; } m_LoopRects.Clear(); if (clip.duration < WindowState.kTimeEpsilon) { return; } var times = TimelineHelpers.GetLoopTimes(clip); var loopDuration = TimelineHelpers.GetLoopDuration(clip); m_MinLoopIndex = -1; // we have a hold, no need to compute all loops if (!supportsLooping) { if (times.Length > 1) { var t = times[1]; float loopTime = (float)(clip.duration - t); m_LoopRects.Add(ProjectRectOnTimeline(new Rect((float)(t + clip.start), 0, loopTime, 0), trackRect, state)); } return; } var range = state.timeAreaShownRange; var visibleStartTime = range.x - clip.start; var visibleEndTime = range.y - clip.start; for (int i = 1; i < times.Length; i++) { var t = times[i]; // don't draw off screen loops if (t > visibleEndTime) { break; } float loopTime = Mathf.Min((float)(clip.duration - t), (float)loopDuration); var loopEnd = t + loopTime; if (loopEnd < visibleStartTime) { continue; } m_LoopRects.Add(ProjectRectOnTimeline(new Rect((float)(t + clip.start), 0, loopTime, 0), trackRect, state)); if (m_MinLoopIndex == -1) { m_MinLoopIndex = i; } } }
public static bool CompleteLastLoop(TimelineClip[] clips) { for (int i = 0; i < clips.Length; i++) { TimelineClip timelineClip = clips[i]; if (TimelineHelpers.HasUsableAssetDuration(timelineClip)) { double[] loopTimes = TimelineHelpers.GetLoopTimes(timelineClip); double loopDuration = TimelineHelpers.GetLoopDuration(timelineClip); TimelineUndo.PushUndo(timelineClip.parentTrack, "Complete Clip Last Loop"); timelineClip.duration = timelineClip.start + loopTimes.LastOrDefault <double>() + loopDuration; } } return(true); }
public static bool TrimLastLoop(TimelineClip[] clips) { for (int i = 0; i < clips.Length; i++) { TimelineClip timelineClip = clips[i]; if (TimelineHelpers.HasUsableAssetDuration(timelineClip)) { double[] loopTimes = TimelineHelpers.GetLoopTimes(timelineClip); double loopDuration = TimelineHelpers.GetLoopDuration(timelineClip); double num = timelineClip.duration - loopTimes.FirstOrDefault <double>(); if (loopDuration > 0.0) { num = (timelineClip.duration - loopTimes.FirstOrDefault <double>()) / loopDuration; } int num2 = Mathf.FloorToInt((float)num); if (num2 > 0) { TimelineUndo.PushUndo(timelineClip.parentTrack, "Trim Clip Last Loop"); timelineClip.duration = loopTimes.FirstOrDefault <double>() + (double)num2 * loopDuration; } } } return(true); }
public IEnumerable <Edge> SnappableEdgesFor(IAttractable attractable, ManipulateEdges manipulateEdges) { var edges = new List <Edge>(); bool canAddEdges = !parent.muted; if (canAddEdges) { // Hack: Trim Start in Ripple mode should not have any snap point added if (EditMode.editType == EditMode.EditType.Ripple && manipulateEdges == ManipulateEdges.Left) { return(edges); } if (attractable != this) { if (EditMode.editType == EditMode.EditType.Ripple) { bool skip = false; // Hack: Since Trim End and Move in Ripple mode causes other snap point to move on the same track (which is not supported), disable snapping for this special cases... // TODO Find a proper way to have different snap edges for each edit mode. if (manipulateEdges == ManipulateEdges.Right) { var otherClipGUI = attractable as TimelineClipGUI; skip = otherClipGUI != null && otherClipGUI.parent == parent; } else if (manipulateEdges == ManipulateEdges.Both) { var moveHandler = attractable as MoveItemHandler; skip = moveHandler != null && moveHandler.movingItems.Any(clips => clips.targetTrack == clip.parentTrack && clip.start >= clips.start); } if (skip) { return(edges); } } AddEdge(edges, clip.start); AddEdge(edges, clip.end); } else { if (manipulateEdges == ManipulateEdges.Right) { var d = TimelineHelpers.GetClipAssetEndTime(clip); if (d < double.MaxValue) { if (clip.SupportsLooping()) { var l = TimelineHelpers.GetLoopDuration(clip); var shownTime = TimelineWindow.instance.state.timeAreaShownRange; do { AddEdge(edges, d, false); d += l; }while (d < shownTime.y); } else { AddEdge(edges, d, false); } } } if (manipulateEdges == ManipulateEdges.Left) { var clipInfo = AnimationClipCurveCache.Instance.GetCurveInfo(clip.animationClip); if (clipInfo != null && clipInfo.keyTimes.Any()) { AddEdge(edges, clip.FromLocalTimeUnbound(clipInfo.keyTimes.Min()), false); } } } } return(edges); }