Пример #1
0
 public void RemoveClip(AnimationClipData clipData)
 {
     if (!this.trackClipList.Contains(clipData))
     {
         throw new Exception("Track doesn't contains Clip");
     }
     this.trackClipList.Remove(clipData);
 }
Пример #2
0
 public void AddClip(AnimationClipData clipData)
 {
     if (this.trackClipList.Contains(clipData))
     {
         throw new Exception("Track already contains Clip");
     }
     this.trackClipList.Add(clipData);
 }
        public void Process(float sequenceTime, float playbackRate)
        {
            this.allClips.Clear();
            for (int i = 0; i < this.AnimationTimeline.AnimationTracks.Count; i++)
            {
                AnimationTrack animationTrack = this.AnimationTimeline.AnimationTracks[i];
                for (int j = 0; j < animationTrack.TrackClips.Count; j++)
                {
                    AnimationClipData animationClipData = animationTrack.TrackClips[j];
                    this.allClips.Add(animationClipData);
                    animationClipData.RunningLayer = animationTrack.Layer;
                }
            }
            float num  = sequenceTime - this.previousTime;
            float num2 = Mathf.Abs(num);
            bool  flag = num < 0f;
            float num3 = USSequencer.SequenceUpdateRate;
            float num4 = this.previousTime + num3;

            if (flag)
            {
                this.AnimationTimeline.ResetAnimation();
                this.previousTime = 0f;
                this.AnimationTimeline.Process(sequenceTime, playbackRate);
            }
            else
            {
                while (num2 > 0f)
                {
                    this.cachedRunningClips.Clear();
                    for (int k = 0; k < this.allClips.Count; k++)
                    {
                        AnimationClipData animationClipData2 = this.allClips[k];
                        if (AnimationClipData.IsClipRunning(num4, animationClipData2))
                        {
                            this.cachedRunningClips.Add(animationClipData2);
                        }
                    }
                    this.cachedRunningClips.Sort((AnimationClipData x, AnimationClipData y) => x.StartTime.CompareTo(y.StartTime));
                    for (int l = 0; l < this.cachedRunningClips.Count; l++)
                    {
                        AnimationClipData animationClipData3 = this.cachedRunningClips[l];
                        this.PlayClip(animationClipData3, animationClipData3.RunningLayer, num4);
                    }
                    this.Animator.Update(num3);
                    num2 -= USSequencer.SequenceUpdateRate;
                    if (!Mathf.Approximately(num2, 1.401298E-45f) && num2 < USSequencer.SequenceUpdateRate)
                    {
                        num3 = num2;
                    }
                    num4 += num3;
                }
            }
            this.previousTime = sequenceTime;
        }
        private void PlayClip(AnimationClipData clipToPlay, int layer, float sequenceTime)
        {
            float normalizedTime = (sequenceTime - clipToPlay.StartTime) / clipToPlay.StateDuration;

            if (clipToPlay.CrossFade)
            {
                float num = clipToPlay.TransitionDuration - (sequenceTime - clipToPlay.StartTime);
                num = Mathf.Clamp(num, 0f, float.PositiveInfinity);
                this.Animator.CrossFade(clipToPlay.StateName, num, layer, normalizedTime);
            }
            else
            {
                this.Animator.Play(clipToPlay.StateName, layer, normalizedTime);
            }
        }
Пример #5
0
 private void SortClipsAtTime(float sequenceTime, IEnumerable <AnimationClipData> sortInto, AnimationClipData.StateCheck stateCheck)
 {
     for (int i = 0; i < this.allClips.Count; i++)
     {
         AnimationClipData animationClipData = this.allClips[i];
         bool flag = sortInto.Contains(animationClipData);
         if (stateCheck(sequenceTime, animationClipData) && !flag)
         {
             if (!this.newProcessingClips.Contains(animationClipData))
             {
                 this.newProcessingClips.Add(animationClipData);
             }
         }
         else if (!stateCheck(sequenceTime, animationClipData) && flag && !this.newProcessingClips.Contains(animationClipData))
         {
             this.newProcessingClips.Add(animationClipData);
         }
     }
 }
        private void RemoveClip(AnimationClipData clip)
        {
            var undoName               = "RemoveClip";
            var animationTracks        = AnimationTimeline.AnimationTracks;
            var cachedClipDataToRemove = cachedClipRenderData.Where(cachedClipData => cachedClipData.animationClipData == clip).ToList();
            var tracksToRemoveClipFrom = animationTracks.Where(track => track.TrackClips.Contains(clip));

            USUndoManager.RegisterCompleteObjectUndo(this, undoName);

            foreach (var cachedClipData in cachedClipDataToRemove)
            {
                cachedClipRenderData.Remove(cachedClipData);
                USUndoManager.DestroyImmediate(cachedClipData);
            }

            foreach (var trackToRemoveClipFrom in tracksToRemoveClipFrom)
            {
                USUndoManager.RegisterCompleteObjectUndo(trackToRemoveClipFrom, undoName);
                trackToRemoveClipFrom.RemoveClip(clip);
                USUndoManager.DestroyImmediate(clip);
            }
        }
        private void PlayClip(AnimationClipData clipToPlay, int layer, float sequenceTime)
        {
            var normalizedTime = (sequenceTime - clipToPlay.StartTime) / clipToPlay.StateDuration;

            if (clipToPlay.CrossFade)
            {
                // The calculation and clamp are here, to resolve issues with big timesteps.
                // crossFadeTime will not always be equal to clipToPlay.transitionDuration, for insance
                // if the timeStep allows for a step of 0.5, we'll be 0.5s into the crossfade.
                var crossFadeTime = clipToPlay.TransitionDuration - (sequenceTime - clipToPlay.StartTime);
                crossFadeTime = Mathf.Clamp(crossFadeTime, 0.0f, Mathf.Infinity);

                Animator.CrossFade(clipToPlay.StateName, crossFadeTime, layer, normalizedTime);
            }
            else
            {
                Animator.Play(clipToPlay.StateName, layer, normalizedTime);
            }

            //var message = string.Format("state: {0}, nt: {1}, cf: {2}", clipToPlay.StateName, normalizedTime, clipToPlay.CrossFade);
            //Debug.LogError(message);
        }
        private void SortNewProcessingClips(float sequenceTime)
        {
            var orderedNewProcessingClips = newProcessingClips.OrderBy(processingClip => processingClip.StartTime);

            foreach (var clipData in orderedNewProcessingClips)
            {
                if (AnimationClipData.IsClipNotRunning(sequenceTime, clipData))
                {
                    notRunningClips.Add(clipData);
                }
                else if (!AnimationClipData.IsClipNotRunning(sequenceTime, clipData) && notRunningClips.Contains(clipData))
                {
                    notRunningClips.Remove(clipData);
                }

                if (AnimationClipData.IsClipRunning(sequenceTime, clipData))
                {
                    runningClips.Add(clipData);
                    PlayClip(clipData, clipData.RunningLayer, sequenceTime);
                }
                else if (!AnimationClipData.IsClipRunning(sequenceTime, clipData) && runningClips.Contains(clipData))
                {
                    runningClips.Remove(clipData);
                }

                if (AnimationClipData.IsClipFinished(sequenceTime, clipData))
                {
                    finishedClips.Add(clipData);
                }
                else if (!AnimationClipData.IsClipFinished(sequenceTime, clipData) && finishedClips.Contains(clipData))
                {
                    finishedClips.Remove(clipData);
                }
            }

            newProcessingClips.Clear();
        }
Пример #9
0
        private void SortNewProcessingClips(float sequenceTime)
        {
            IOrderedEnumerable <AnimationClipData> orderedEnumerable = from processingClip in this.newProcessingClips
                                                                       orderby processingClip.StartTime
                                                                       select processingClip;

            foreach (AnimationClipData current in orderedEnumerable)
            {
                if (AnimationClipData.IsClipNotRunning(sequenceTime, current))
                {
                    this.notRunningClips.Add(current);
                }
                else if (!AnimationClipData.IsClipNotRunning(sequenceTime, current) && this.notRunningClips.Contains(current))
                {
                    this.notRunningClips.Remove(current);
                }
                if (AnimationClipData.IsClipRunning(sequenceTime, current))
                {
                    this.runningClips.Add(current);
                    this.PlayClip(current, current.RunningLayer, sequenceTime);
                }
                else if (!AnimationClipData.IsClipRunning(sequenceTime, current) && this.runningClips.Contains(current))
                {
                    this.runningClips.Remove(current);
                }
                if (AnimationClipData.IsClipFinished(sequenceTime, current))
                {
                    this.finishedClips.Add(current);
                }
                else if (!AnimationClipData.IsClipFinished(sequenceTime, current) && this.finishedClips.Contains(current))
                {
                    this.finishedClips.Remove(current);
                }
            }
            this.newProcessingClips.Clear();
        }
Пример #10
0
 public static bool IsClipFinished(float sequencerTime, AnimationClipData clipData)
 {
     return(sequencerTime >= clipData.EndTime);
 }
Пример #11
0
 public static bool IsClipRunning(float sequencerTime, AnimationClipData clipData)
 {
     return(sequencerTime > clipData.StartTime && sequencerTime < clipData.EndTime);
 }
        public void Process(float sequenceTime, float playbackRate)
        {
            allClips.Clear();
            for (var index = 0; index < AnimationTimeline.AnimationTracks.Count; index++)
            {
                var track = AnimationTimeline.AnimationTracks[index];

                for (var trackClipIndex = 0; trackClipIndex < track.TrackClips.Count; trackClipIndex++)
                {
                    var trackClip = track.TrackClips[trackClipIndex];
                    allClips.Add(trackClip);
                    trackClip.RunningLayer = track.Layer;
                }
            }

            var totalDeltaTime           = sequenceTime - previousTime;
            var absDeltaTime             = Mathf.Abs(totalDeltaTime);
            var timelinePlayingInReverse = totalDeltaTime < 0.0f;
            var runningTime      = USSequencer.SequenceUpdateRate;
            var runningTotalTime = previousTime + runningTime;

            if (timelinePlayingInReverse)
            {
                AnimationTimeline.ResetAnimation();
                previousTime = 0.0f;
                AnimationTimeline.Process(sequenceTime, playbackRate);
            }
            else
            {
                while (absDeltaTime > 0.0f)
                {
                    cachedRunningClips.Clear();
                    for (var allClipIndex = 0; allClipIndex < allClips.Count; allClipIndex++)
                    {
                        var clip = allClips[allClipIndex];
                        if (!AnimationClipData.IsClipRunning(runningTotalTime, clip))
                        {
                            continue;
                        }

                        cachedRunningClips.Add(clip);
                    }

                    cachedRunningClips.Sort((x, y) => x.StartTime.CompareTo(y.StartTime));

                    for (var runningClipIndex = 0; runningClipIndex < cachedRunningClips.Count; runningClipIndex++)
                    {
                        var clip = cachedRunningClips[runningClipIndex];
                        PlayClip(clip, clip.RunningLayer, runningTotalTime);
                    }

                    Animator.Update(runningTime);

                    absDeltaTime -= USSequencer.SequenceUpdateRate;
                    if (!Mathf.Approximately(absDeltaTime, Mathf.Epsilon) && absDeltaTime < USSequencer.SequenceUpdateRate)
                    {
                        runningTime = absDeltaTime;
                    }

                    runningTotalTime += runningTime;
                }
            }

            previousTime = sequenceTime;
        }