/// <summary>
        /// Implements the update code so it can be reused.
        /// </summary>
        virtual protected void ActualUpdate()
        {
            if (ensureStatePlaysForOneFrame)
            {
                // Ensure we played the state for at least one frame, this is to work around for Mecanim issue where calling Play isn't always playing the animation
                if (myAnimator.GetCurrentAnimatorStateInfo(0).IsName(state.AsString()))
                {
                    hasPlayed = true;
                    myAnimator.SetBool("HasPlayed", true);
                    // Now play the queued state
                    if (queuedState != AnimationState.NONE)
                    {
                        myAnimator.SetInteger("PreviousState", (int)state);
                        myAnimator.SetInteger("State", (int)queuedState);
                        state       = queuedState;
                        queuedState = AnimationState.NONE;
                        hasPlayed   = false;
                        myAnimator.SetBool("HasPlayed", false);
                    }
                }
            }

            // If we have an aimer set the gun variables
            if (aimer != null)
            {
                Vector2 aimDirection = aimer.GetAimDirection((Character)myCharacter);
                myAnimator.SetFloat("GunPositionX", aimDirection.x);
                myAnimator.SetFloat("GunPositionY", aimDirection.y);
            }

            // Set velocity vars
            myAnimator.SetFloat("VelocityX", myCharacter.Velocity.x);
            myAnimator.SetFloat("VelocityY", myCharacter.Velocity.y);
            myAnimator.SetInteger("FacingDirection", myCharacter.FacingDirection);
        }
        /// <summary>
        /// Fire projectile then temporarily set an animation override.
        /// </summary>
        virtual protected IEnumerator ShootRoutine()
        {
            // Instantiate prefab

            GameObject go         = (GameObject)GameObject.Instantiate(projectilePrefab);
            Projectile projectile = go.GetComponent <Projectile>();

            if (projectileAimer != null)
            {
                go.transform.position = enemy.transform.position + (Vector3)projectileAimer.GetAimOffset(enemy);
            }
            else
            {
                go.transform.position = enemy.transform.position;
            }

            if (projectile != null)
            {
                // Fire projectile if the projectile is of type projectile
                Vector2 direction = new Vector2(enemy.LastFacedDirection != 0 ? enemy.LastFacedDirection : 1, 0);
                // Use aimer to get direction fo fire if the aimer is configured
                if (projectileAimer != null)
                {
                    direction = projectileAimer.GetAimDirection(enemy);
                }
                projectile.Fire(damageAmount, damageType, direction, enemy);
            }

            enemy.AddAnimationOverride(overrideName);
            isShooting = true;
            yield return(new WaitForSeconds(shootTime));

            enemy.RemoveAnimationOverride(overrideName);
            isShooting = false;
        }
예제 #3
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);
        }
예제 #4
0
        /// <summary>
        /// Fires the grapple.
        /// </summary>
        virtual protected void FireGrapple()
        {
            if (ropeGo == null)
            {
                ropeGo = (GameObject)GameObject.Instantiate(ropePrefab);
                ropeGo.SetActive(false);
            }
            // Instantiate grapple first time
            if (grapple == null)
            {
                GameObject go = (GameObject)GameObject.Instantiate(grapplePrefab);
                grapple = go.GetComponent <GrapplingHookProjectile> ();
            }

            // Fire grapple
            grapple.transform.position = character.Transform.position + (Vector3)(aimer == null ? Vector2.zero : aimer.GetAimOffset(character));
            grapple.Fire(0, DamageType.NONE, aimer == null ? new Vector2(0, 1) : aimer.GetAimDirection(character), character);
            maxRopeDistance = 0;
        }
예제 #5
0
 /// <summary>
 /// Unity update hook, face correct direction.
 /// </summary>
 void Update()
 {
     if (enabled && !TimeManager.Instance.Paused)
     {
         float dir = myAimer.GetAimDirection((Component)animatable).x;
         if (dir > 0)
         {
             transform.localScale = new Vector3((flipLeftAndRight ? -1 : 1) * cachedScale.x, cachedScale.y, cachedScale.z);
             if (flipSpriteOffset)
             {
                 transform.localPosition = new Vector3((flipLeftAndRight ? -1 : 1) * cachedOffset.x, cachedOffset.y, cachedOffset.z);
             }
         }
         else if (dir < 0)
         {
             transform.localScale = new Vector3((flipLeftAndRight ? 1 : -1) * cachedScale.x, cachedScale.y, cachedScale.z);
             if (flipSpriteOffset)
             {
                 transform.localPosition = new Vector3((flipLeftAndRight ? 1 : -1) * cachedOffset.x, cachedOffset.y, cachedOffset.z);
             }
         }
     }
 }
예제 #6
0
        /// <summary>
        /// Instatiates a projectile.
        /// </summary>
        /// <param name="attackIndex">Index of the projectile to instantiate.</param>
        virtual public void InstantiateProjectile(int attackIndex)
        {
            // If attack index == -1 then we should use the deferred attack.
            if (attackIndex == -1)
            {
                attackIndex = deferredAttackIndex;
            }
            // Instantiate prefab
            GameObject go         = (GameObject)GameObject.Instantiate(attacks[attackIndex].projectilePrefab);
            Projectile projectile = go.GetComponent <Projectile>();

            if (projectileAimer != null)
            {
                go.transform.position = character.transform.position + (Vector3)projectileAimer.GetAimOffset(character);
            }
            else
            {
                go.transform.position = character.transform.position;
            }

            if (projectile != null)
            {
                // Fire projectile if the projectile is of type projectile
                Vector2 direction = new Vector2(character.LastFacedDirection != 0 ? character.LastFacedDirection : 1, 0);
                // Use aimer to get direction fo fire if the aimer is configured
                if (projectileAimer != null)
                {
                    direction = projectileAimer.GetAimDirection(character);
                }
                projectile.Fire(attacks[attackIndex].damageAmount, attacks[attackIndex].damageType, direction, character);
            }
            // If the projectile is found and the go is still alive call finish
            if (projectile != null && go != null)
            {
                projectile.Finish();
            }
        }