Example #1
0
        public static void SetStart(TimelineClip clip, double time)
        {
            var supportsClipIn  = clip.SupportsClipIn();
            var supportsPadding = TimelineUtility.IsRecordableAnimationClip(clip);

            // treat empty recordable clips as not supporting clip in (there are no keys to modify)
            if (supportsPadding && (clip.animationClip == null || clip.animationClip.empty))
            {
                supportsClipIn = false;
            }

            if (supportsClipIn && !supportsPadding)
            {
                var minStart = clip.FromLocalTimeUnbound(0.0);
                if (time < minStart)
                {
                    time = minStart;
                }
            }

            var maxStart = clip.end - TimelineClip.kMinDuration;

            if (time > maxStart)
            {
                time = maxStart;
            }

            var timeOffset = time - clip.start;
            var duration   = clip.duration - timeOffset;

            if (supportsClipIn)
            {
                if (supportsPadding)
                {
                    double clipInGlobal = clip.clipIn / clip.timeScale;
                    double keyShift     = -timeOffset;
                    if (timeOffset < 0) // left drag, eliminate clipIn before shifting
                    {
                        double clipInDelta = Math.Max(-clipInGlobal, timeOffset);
                        keyShift     = -Math.Min(0, timeOffset - clipInDelta);
                        clip.clipIn += clipInDelta * clip.timeScale;
                    }
                    else if (timeOffset > 0) // right drag, elimate padding in animation clip before adding clip in
                    {
                        var    clipInfo = AnimationClipCurveCache.Instance.GetCurveInfo(clip.animationClip);
                        double keyDelta = clip.FromLocalTimeUnbound(clipInfo.keyTimes.Min()) - clip.start;
                        keyShift     = -Math.Max(0, Math.Min(timeOffset, keyDelta));
                        clip.clipIn += Math.Max(timeOffset + keyShift, 0) * clip.timeScale;
                    }
                    if (keyShift != 0)
                    {
                        AnimationTrackRecorder.ShiftAnimationClip(clip.animationClip, (float)(keyShift * clip.timeScale));
                    }
                }
                else
                {
                    clip.clipIn += timeOffset * clip.timeScale;
                }
            }

            clip.start    = time;
            clip.duration = duration;
            clip.ConformEaseValues();
        }
Example #2
0
        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);
        }