Beispiel #1
0
        /// <summary>
        /// Instantly begins the specified clip
        /// </summary>
        /// <param name="parameters"></param>
        /// <param name="clearQueue"></param>
        public void InterruptClip(ClipPlaybackParameters parameters, bool clearQueue = true)
        {
            if (clearQueue)
                _animationQueue.Clear();

            if (parameters.Clip == null)
                parameters = DefaultClip;

            parameters.Clip.Start();

            _fadingIn = PlayingClip.Create(parameters, _animation.BonesCount);
            _fadingIn.TimeFactor = 1;
            _fadingIn.Loop = parameters.Loop;
            _fadingIn.FadeOutTime = parameters.FadeOutTime;

            _crossfadeProgress = 0;
            var fadeOutTime = _fadingOut == null ? 0 : _fadingOut.FadeOutTime.Ticks;
            _crossfadeDuration = TimeSpan.FromTicks(Math.Max(parameters.FadeInTime.Ticks, fadeOutTime));
            _crossfadeElapsed = TimeSpan.Zero;
        }
Beispiel #2
0
        private void UpdateActiveAnimations(TimeSpan dt, out Transform fadingInRootDelta, out Transform fadingOutRootDelta)
        {
            fadingInRootDelta = Transform.Identity;
            fadingOutRootDelta = Transform.Identity;

            if (_fadingOut == null && _fadingIn == null)
                InterruptClip(NextClip(), false);

            if (_fadingOut == null && _fadingIn != null)
            {
                //DO NOT merge this into the if check above.
                //The above can change the state of _fadingOut so we do need to check it twice!
                _fadingOut = _fadingIn;
                _fadingIn = null;
            }

            if (_fadingOut != null)
            {
                _fadingOut.Update(dt, out fadingOutRootDelta);

                //Check if this animation is entering it's final phase. If so, look for another animation in the queue to start playing
                if (_fadingIn == null && _fadingOut.ElapsedTime >= _fadingOut.Animation.Duration - _fadingOut.FadeOutTime && (_animationQueue.Count > 0 || !_fadingOut.Loop))
                    InterruptClip(NextClip(), false);
            }

            if (_fadingIn != null)
            {
                _fadingIn.Update(dt, out fadingInRootDelta);

                _crossfadeElapsed += dt;
                _crossfadeProgress = (float)_crossfadeElapsed.TotalSeconds / (float)_crossfadeDuration.TotalSeconds;

                if (_crossfadeElapsed >= _crossfadeDuration)
                {
                    _fadingOut = _fadingIn;
                    _fadingIn = null;
                }
            }
        }
Beispiel #3
0
 internal static void Return(PlayingClip playing)
 {
     playing.Animation = null;
     _pool.Return(playing);
 }