Exemple #1
0
        /// <summary>
        /// Unity Update hook.
        /// </summary>
        void Update()
        {
            stateChangedThisFrame = false;
            // If we have a new animation to play
            if (queuedStates.Count > 0)
            {
                string            nextState    = queuedStates.Peek();
                int               nextPriority = queuedPriorities.Peek();
                AnimatorStateInfo info         = myAnimator.GetCurrentAnimatorStateInfo(0);
                // Ensure we played the current state for at least one frame, this is to work around for Mecanim issue where calling Play isn't always playing the animation
                if (state == AnimationState.NONE.AsString() || info.IsName(state))
                {
                    // Next animation has higher priority, play it now
                    if (nextPriority >= priority || info.normalizedTime >= 1.0f)                      // || info.loop)
                    {
                        myAnimator.Play(nextState);
                        state    = nextState;
                        priority = nextPriority;
                        queuedStates.Dequeue();
                        queuedPriorities.Dequeue();
                        stateChangedThisFrame = true;
                    }
                }
            }

            // If we have an aimer set the gun variables
            if (aimer != null)
            {
                Vector2 aimDirection    = aimer.GetAimDirection((Character)myCharacter);
                int     aimDirectionInt = GetYAimAsInt(aimDirection);
                if (aimDirectionInt != previousAimDirection)
                {
                    animationEventArgs.UpdateAnimationEventArgs(myCharacter.AnimationState, myCharacter.AnimationState, myCharacter.OverrideState);
                    if (!stateChangedThisFrame)
                    {
                        AnimationStateChanged(this, animationEventArgs);
                    }
                }
                previousAimDirection = aimDirectionInt;
            }
            animationEventArgs = new AnimationEventArgs(AnimationState.NONE, AnimationState.NONE, null);
        }