private void SetAnimationEntry(QueuedAnimation entry)
        {
            previous = null;

            QueuedAnimation current = this.current;

            if (current != null)
            {
                current.OnEnd(this);
                if (End != null)
                {
                    End(this, EventArgs.Empty);
                }

                mixDuration = data.GetMix(current.animation, entry.animation);
                if (mixDuration > 0)
                {
                    mixTime  = 0;
                    previous = current;
                }
            }
            this.current = entry;

            entry.OnStart(this);
            if (Start != null)
            {
                Start(this, EventArgs.Empty);
            }
        }
Esempio n. 2
0
        private void SetCurrent(int index, TrackEntry entry)
        {
            TrackEntry current = ExpandToIndex(index);

            if (current != null)
            {
                current.previous = null;

                current.OnEnd(this, index);
                if (End != null)
                {
                    End(this, new StartEndArgs(index));
                }

                entry.mixDuration = data.GetMix(current.animation, entry.animation);
                if (entry.mixDuration > 0)
                {
                    entry.mixTime  = 0;
                    entry.previous = current;
                }
            }

            tracks[index] = entry;

            entry.OnStart(this, index);
            if (Start != null)
            {
                Start(this, new StartEndArgs(index));
            }
        }
Esempio n. 3
0
        public TrackEntry AddAnimation(int trackIndex, Animation animation, bool loop, float delay)
        {
            if (animation == null)
            {
                throw new ArgumentNullException("animation", "animation cannot be null.");
            }
            TrackEntry trackEntry = ExpandToIndex(trackIndex);

            if (trackEntry != null)
            {
                while (trackEntry.next != null)
                {
                    trackEntry = trackEntry.next;
                }
            }
            TrackEntry trackEntry2 = NewTrackEntry(trackIndex, animation, loop, trackEntry);

            if (trackEntry == null)
            {
                SetCurrent(trackIndex, trackEntry2, interrupt: true);
                queue.Drain();
            }
            else
            {
                trackEntry.next = trackEntry2;
                if (delay <= 0f)
                {
                    float num = trackEntry.animationEnd - trackEntry.animationStart;
                    delay = ((num == 0f) ? 0f : (delay + (num * (float)(1 + (int)(trackEntry.trackTime / num)) - data.GetMix(trackEntry.animation, animation))));
                }
            }
            trackEntry2.delay = delay;
            return(trackEntry2);
        }
Esempio n. 4
0
        /// <summary>Adds an animation to be played delay seconds after the current or last queued animation
        /// for a track. If the track is empty, it is equivalent to calling <see cref="SetAnimation"/>.</summary>
        /// <param name="delay">
        /// Seconds to begin this animation after the start of the previous animation. May be &lt;= 0 to use the animation
        /// duration of the previous track minus any mix duration plus the negative delay.
        /// </param>
        /// <returns>A track entry to allow further customization of animation playback. References to the track entry must not be kept
        /// after <see cref="AnimationState.Dispose"/></returns>
        public TrackEntry AddAnimation(int trackIndex, Animation animation, bool loop, float delay)
        {
            if (animation == null)
            {
                throw new ArgumentNullException("animation", "animation cannot be null.");
            }

            TrackEntry last = ExpandToIndex(trackIndex);

            if (last != null)
            {
                while (last.next != null)
                {
                    last = last.next;
                }
            }

            TrackEntry entry = NewTrackEntry(trackIndex, animation, loop, last);

            if (last == null)
            {
                SetCurrent(trackIndex, entry, true);
                queue.Drain();
            }
            else
            {
                last.next = entry;
                if (delay <= 0)
                {
                    float duration = last.animationEnd - last.animationStart;
                    if (duration != 0)
                    {
                        delay += duration * (1 + (int)(last.trackTime / duration)) - data.GetMix(last.animation, animation);
                    }
                    else
                    {
                        delay = 0;
                    }
                }
            }

            entry.delay = delay;
            return(entry);
        }
Esempio n. 5
0
        private void SetCurrent(int index, TrackEntry entry)
        {
            TrackEntry current = ExpandToIndex(index);

            if (current != null)
            {
                TrackEntry previous = current.previous;
                current.previous = null;

                current.OnEnd(this, index);
                if (End != null)
                {
                    End(this, index);
                }

                entry.mixDuration = data.GetMix(current.animation, entry.animation);
                if (entry.mixDuration > 0)
                {
                    entry.mixTime = 0;
                    // If a mix is in progress, mix from the closest animation.
                    if (previous != null && current.mixTime / current.mixDuration < 0.5f)
                    {
                        entry.previous = previous;
                    }
                    else
                    {
                        entry.previous = current;
                    }
                }
            }

            tracks[index] = entry;

            entry.OnStart(this, index);
            if (Start != null)
            {
                Start(this, index);
            }
        }