public static TimelineClip CreateClipOnTrack(Object asset, TrackAsset parentTrack, ITimelineState state, Vector2 mousePosition) { double end = parentTrack.end; TimelineClip timelineClip = parentTrack.CreateClipFromAsset(asset); if (timelineClip != null) { SelectionManager.Clear(); timelineClip.timeScale = 1.0; if (!float.IsPositiveInfinity(mousePosition.x) && !float.IsPositiveInfinity(mousePosition.y)) { timelineClip.start = (double)state.ScreenSpacePixelToTimeAreaTime(mousePosition.x); } else { timelineClip.start = state.SnapToFrameIfRequired(end); } timelineClip.start = Math.Max(0.0, timelineClip.start); timelineClip.mixInCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f); timelineClip.mixOutCurve = AnimationCurve.EaseInOut(0f, 1f, 1f, 0f); SelectionManager.Add(timelineClip); parentTrack.CalculateExtrapolationTimes(); state.Refresh(); } return(timelineClip); }
public static TimelineClip AddRecordableClip(TrackAsset parentTrack, TimelineWindow.TimelineState state) { TimelineAsset timeline = state.timeline; TimelineClip result; if (timeline == null) { Debug.LogError("Parent Track needs to be bound to an asset to add a recordable"); result = null; } else { AnimationClip animationClip = new AnimationClip(); animationClip.set_name(AnimationTrackRecorder.GetUniqueRecordedClipName(parentTrack, AnimationTrackRecorder.kRecordClipDefaultName)); animationClip.set_frameRate(state.frameRate); AnimationUtility.SetGenerateMotionCurves(animationClip, true); Undo.RegisterCreatedObjectUndo(animationClip, "Create Clip"); TimelineHelpers.SaveAnimClipIntoObject(animationClip, parentTrack); TimelineClip timelineClip = parentTrack.CreateClipFromAsset(animationClip); if (timelineClip != null) { timelineClip.recordable = true; timelineClip.displayName = animationClip.get_name(); timelineClip.timeScale = 1.0; timelineClip.start = 0.0; timelineClip.duration = 0.0; timelineClip.mixInCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f); timelineClip.mixOutCurve = AnimationCurve.EaseInOut(0f, 1f, 1f, 0f); timelineClip.preExtrapolationMode = TimelineClip.ClipExtrapolation.Hold; timelineClip.postExtrapolationMode = TimelineClip.ClipExtrapolation.Hold; TimelineCreateUtilities.SaveAssetIntoObject(timelineClip.asset, parentTrack); state.Refresh(); } result = timelineClip; } return(result); }