Exemple #1
0
        public void Step()
        {
            //this is under a timer an needs

            AgentAnimation animation = this.currentAnimation;
            var            frame     = this.currentFrame;

            if (animation == null)
            {
                return;
            }

            var newFrameIndex = Math.Min(this.GetNextAnimationFrame(), animation.Frames.Count - 1);
            var frameChanged  = frame != null && this.currentFrameIndex != newFrameIndex;

            this.currentFrameIndex = newFrameIndex;

            // always switch frame data, unless we're at the last frame of an animation with a useExitBranching flag.
            if (!(this.IsAtLastFrame() && animation.UseExitBranching))
            {
                currentFrame = frame = animation.Frames[this.currentFrameIndex];
            }

            if (frame.Duration > 0)
            {
                NeedsRefresh?.Invoke(this, EventArgs.Empty);
                agent.PlaySound(currentFrame?.Sound);

                aTimer.Interval = frame.Duration;
                aTimer.Start();
            }

            if (frameChanged && this.IsAtLastFrame())
            {
                _started = false;
                if (animation.UseExitBranching && !this._exiting)
                {
                    AnimationEnded?.Invoke(this, new AnimationStateEventArgs(currentAnimationName, AnimationStates.Waiting));
                }
                else
                {
                    AnimationEnded?.Invoke(this, new AnimationStateEventArgs(currentAnimationName, AnimationStates.Exited));
                }
            }
        }
Exemple #2
0
        public bool ShowAnimation(string animationName)
        {
            this._exiting = false;
            if (!this.HasAnimation(animationName))
            {
                return(false);
            }

            this.currentAnimation     = Animations.FirstOrDefault(s => s.Name == animationName);
            this.currentAnimationName = animationName;

            if (!this._started)
            {
                this.Step();
                this._started = true;
            }

            this.currentFrame      = null;
            this.currentFrameIndex = 0;
            return(true);
        }