// Given a track, return the animation clip internal static AnimationClip FindRecordingAnimationClipAtTime(this TrackAsset trackAsset, double time) { if (trackAsset == null) return null; AnimationTrack animTrack = trackAsset as AnimationTrack; if (animTrack != null && !animTrack.inClipMode) { return animTrack.infiniteClip; } TimelineClip displayBackground = null; trackAsset.FindRecordingClipAtTime(time, out displayBackground); if (displayBackground != null) { if (displayBackground.recordable) { AnimationPlayableAsset asset = displayBackground.asset as AnimationPlayableAsset; if (asset != null) return asset.clip; } else if (animTrack == null) { AnimatedParameterExtensions.CreateCurvesIfRequired(displayBackground); return displayBackground.curves; } } return null; }
static void DrawBorderOfAddedRecordingClip(Rect trackRect, TrackAsset trackAsset, Vector2 visibleTime, WindowState state) { if (!state.IsArmedForRecord(trackAsset)) { return; } AnimationTrack animTrack = trackAsset as AnimationTrack; if (animTrack == null || !animTrack.inClipMode) { return; } // make sure there is no clip but we can add one TimelineClip clip = null; if (trackAsset.FindRecordingClipAtTime(state.editSequence.time, out clip) || clip != null) { return; } float yMax = trackRect.yMax; float yMin = trackRect.yMin; double startGap = 0; double endGap = 0; trackAsset.GetGapAtTime(state.editSequence.time, out startGap, out endGap); if (double.IsInfinity(endGap)) { endGap = visibleTime.y; } if (startGap > visibleTime.y || endGap < visibleTime.x) { return; } startGap = Math.Max(startGap, visibleTime.x); endGap = Math.Min(endGap, visibleTime.y); float xMin = state.TimeToPixel(startGap); float xMax = state.TimeToPixel(endGap); Rect r = Rect.MinMaxRect(xMin, yMin, xMax, yMax); ClipDrawer.DrawBorder(r, ClipBorder.kRecording, ClipBlends.kNone); }
// Given a track, return the animation clip internal static AnimationClip FindRecordingAnimationClipAtTime(this TrackAsset trackAsset, double time) { if (trackAsset == null) { return(null); } AnimationTrack animTrack = trackAsset as AnimationTrack; if (animTrack != null && !animTrack.inClipMode) { return(animTrack.infiniteClip); } TimelineClip displayBackground; trackAsset.FindRecordingClipAtTime(time, out displayBackground); if (displayBackground != null) { if (displayBackground.recordable) { AnimationPlayableAsset asset = displayBackground.asset as AnimationPlayableAsset; if (asset != null) { return(asset.clip); } } else if (animTrack == null) { if (displayBackground.curves == null) { displayBackground.CreateCurves(AnimationTrackRecorder.GetUniqueRecordedClipName(displayBackground.parentTrack, TimelineClip.kDefaultCurvesName)); } return(displayBackground.curves); } } else if (trackAsset.HasAnyAnimatableParameters()) { if (trackAsset.curves == null) { trackAsset.CreateCurves(AnimationTrackRecorder.GetUniqueRecordedClipName(trackAsset.timelineAsset, TrackAsset.kDefaultCurvesName)); } return(trackAsset.curves); } return(null); }
// Given an animation track, return the clip that we are currently recording to static AnimationClip GetRecordingClip(TrackAsset asset, WindowState state, out double startTime, out double timeScale) { startTime = 0; timeScale = 1; TimelineClip displayBackground = null; asset.FindRecordingClipAtTime(state.editSequence.time, out displayBackground); var animClip = asset.FindRecordingAnimationClipAtTime(state.editSequence.time); if (displayBackground != null) { startTime = displayBackground.start; timeScale = displayBackground.timeScale; } return(animClip); }
internal static AnimationClip FindRecordingAnimationClipAtTime(this TrackAsset trackAsset, double time) { AnimationClip result; if (trackAsset == null) { result = null; } else { AnimationTrack animationTrack = trackAsset as AnimationTrack; if (animationTrack != null && !animationTrack.inClipMode) { result = animationTrack.animClip; } else { TimelineClip timelineClip = trackAsset.FindRecordingClipAtTime(time); if (timelineClip != null) { AnimationPlayableAsset animationPlayableAsset = timelineClip.asset as AnimationPlayableAsset; if (animationPlayableAsset != null) { result = animationPlayableAsset.clip; } else { AnimatedParameterExtensions.CreateCurvesIfRequired(timelineClip, null); result = timelineClip.curves; } } else { result = null; } } } return(result); }
public AnimationClip PrepareTrack(TrackAsset track, WindowState state, GameObject gameObject, out double startTime) { AnimationClip animationClip = null; // if we are not in clip mode, we simply use the track clip var animationTrack = (AnimationTrack)track; // ignore recording if we are in Legacy auto mode startTime = -1; var parentTrack = TimelineUtility.GetSceneReferenceTrack(track) as AnimationTrack; if (parentTrack != null && parentTrack.trackOffset == TrackOffset.Auto) { return(null); } if (!animationTrack.inClipMode) { var trackClip = animationTrack.GetOrCreateClip(); startTime = trackClip.frameRate * state.editSequence.time; // Make the first key be at time 0 of the clip if (trackClip.empty) { animationTrack.infiniteClipTimeOffset = 0; // state.time; animationTrack.infiniteClipPreExtrapolation = TimelineClip.ClipExtrapolation.Hold; animationTrack.infiniteClipPostExtrapolation = TimelineClip.ClipExtrapolation.Hold; } animationClip = trackClip; } else { TimelineClip activeClip = null; // if it fails, but returns no clip, we can add one. if (!track.FindRecordingClipAtTime(state.editSequence.time, out activeClip) && activeClip != null) { return(null); } if (activeClip == null) { activeClip = AddRecordableClip(track, state, state.editSequence.time); } var clip = activeClip.animationClip; // flags this as the clip being recorded for the track var clipTime = state.editSequence.time - activeClip.start; // if we are in the past if (clipTime < 0) { Undo.RegisterCompleteObjectUndo(clip, "Record Key"); UndoExtensions.RegisterTrack(track, "Prepend Key"); ShiftAnimationClip(clip, (float)-clipTime); activeClip.start = state.editSequence.time; activeClip.duration += -clipTime; clipTime = 0; } m_ClipTime = clipTime; recordClip = activeClip; startTime = recordClip.ToLocalTimeUnbound(state.editSequence.time) * clip.frameRate; m_needRebuildRects = clip.empty; animationClip = clip; } m_TargetClip = animationClip; m_CurveCount = GetCurveCount(animationClip); m_TrackHasPreviewComponents = animationTrack.hasPreviewComponents; return(animationClip); }
public AnimationClip PrepareTrack(TrackAsset track, TimelineWindow.TimelineState state, GameObject gameObject, out double startTime) { AnimationTrack animationTrack = (AnimationTrack)track; AnimationClip result; if (!animationTrack.inClipMode) { AnimationClip orCreateClip = animationTrack.GetOrCreateClip(); startTime = (double)orCreateClip.get_frameRate() * state.time; if (!this.m_TracksToProcess.Contains(animationTrack)) { this.m_TracksToProcess.Add(animationTrack); } this.m_RebindList.Add(gameObject); if (orCreateClip.get_empty()) { animationTrack.openClipTimeOffset = 0.0; animationTrack.openClipPreExtrapolation = TimelineClip.ClipExtrapolation.Hold; animationTrack.openClipPostExtrapolation = TimelineClip.ClipExtrapolation.Hold; } result = orCreateClip; } else { TimelineClip timelineClip = AnimationTrackRecorder.GetRecordingClipForTrack(track, state); if (timelineClip == null) { timelineClip = track.FindRecordingClipAtTime(state.time); } List <TimelineClip> list = (from x in track.clips where x.start <= state.time && x.end >= state.time select x).ToList <TimelineClip>(); if (timelineClip == null) { if (list.Count != 0) { if (list.Count > 0) { if (list.Any((TimelineClip x) => x.recordable)) { goto IL_12A; } } Debug.LogWarning("Cannot record on top of an imported animation clip"); startTime = -1.0; result = null; return(result); } IL_12A: timelineClip = AnimationTrackRecorder.AddRecordableClip(track, state); timelineClip.start = state.time; this.m_RebindList.Add(gameObject); } AnimationClip animationClip = timelineClip.animationClip; double num = state.time - timelineClip.start; if (num < 0.0) { Undo.RegisterCompleteObjectUndo(animationClip, "Record Key"); TimelineUndo.PushUndo(track, "Prepend Key"); AnimationTrackRecorder.ShiftAnimationClip(animationClip, (float)(-(float)num)); timelineClip.start = state.time; timelineClip.duration += -num; num = 0.0; this.m_RefreshState = true; } this.m_ClipTime = num; this.recordClip = timelineClip; startTime = (double)TimeUtility.ToFrames(this.recordClip.ToLocalTimeUnbound(state.time), (double)animationClip.get_frameRate()); this.m_needRebuildRects = animationClip.get_empty(); result = animationClip; } return(result); }
private static TimelineClip GetRecordingClipForTrack(TrackAsset track, TimelineWindow.TimelineState state) { return(track.FindRecordingClipAtTime(state.time)); }