public void PlayAnimation(string animation, bool lockAnimation = false)
 {
     if (!animationChangeLock && !character.dead)
     {
         animationChangeLock = lockAnimation;
         Debug.Log(this.name + " play animation: " + animation + " lock:" + lockAnimation);
         animationController.Play(animation);
         currentAnimationState = AnimationsStates.Custom;
     }
 }
 public void PlayArmsAnimation(AnimationsStates state)
 {
     if (armsAnimationController)
     {
         if (currentArmsAnimationState != state)
         {
             Debug.Log("Play arms animation:" + state);
             armsAnimationController.Play(state.ToString());
             currentArmsAnimationState = state;
         }
     }
 }
 public void PlayAnimation(AnimationsStates state, bool lockAnimation = false)
 {
     //TODO get rid of character.dead checking
     if (!animationChangeLock && !character.dead)
     {
         animationChangeLock = lockAnimation;
         if (currentAnimationState != state)
         {
             //Debug.Log (this.name + " play animation: " + state.ToString () + " lock:" + lockAnimation);
             animationController.Play(state.ToString());
             currentAnimationState = state;
         }
     }
 }
 public void StopBlocking()
 {
     if (character.blocking)
     {
         if (character != null)
         {
             character.StopBlocking();
         }
         if (armsAnimationController)
         {
             armsAnimationController.gameObject.SetActive(false);
             currentArmsAnimationState = AnimationsStates.Custom;
         }
     }
 }
 // Use this for initialization
 void Start()
 {
     currentSpeed          = runSpeed;
     rigidBody             = GetComponent <Rigidbody2D> ();
     character             = GetComponent <SNCharacter> ();
     topDownPhysics        = GetComponent <TopDownPhysics> ();
     currentAnimationState = AnimationsStates.Custom;
     if (rigidBody.isKinematic)
     {
         useKinematic = true;
     }
     else
     {
         useKinematic = false;
     }
 }
    public void MoveUpdate(Vector2 move, Vector2 aim)
    {
        if (move.magnitude > 0.001f)
        {
            lastInputMove = move.normalized;
        }
        else
        {
            if (aim.magnitude > 0.001f)
            {
                lastInputMove = aim.normalized;
            }
        }
        if (canMove)
        {
            if (character != null)
            {
                if (aim.magnitude > 0.001f)
                {
                    if (!character.aiming)
                    {
                        if (character != null)
                        {
                            if (!character.blocking)
                            {
                                character.StartAiming();
                            }
                        }
                    }
                }
                else
                {
                    if ((character) && (character.aiming) && (!character.forceAiming))
                    {
                        character.EndAiming();
                        if (armsAnimationController)
                        {
                            armsAnimationController.gameObject.SetActive(false);
                            currentArmsAnimationState = AnimationsStates.Custom;
                        }
                    }
                }
                if (aim.magnitude <= 0.001f)
                {
                    aim = lastInputMove;
                }
                aimDirection = aim;
                if (character.blocking || character.aiming)
                {
                    currentSpeed = walkSpeed;
                    if (armsAnimationController)
                    {
                        armsAnimationController.gameObject.SetActive(true);
                    }
                    if (moveVelocity.magnitude > 0.001f)
                    {
                        AnimationsStates newAnimState = AnimationsStates.Block;
                        Vector3          newArmsPos;
                        Vector3          newAnimationFixedDirection;

                        if (Mathf.Abs(aim.x) > Mathf.Abs(aim.y))
                        {
                            if (aim.x > 0)
                            {
                                newAnimState = AnimationsStates.BlockWalkRight;
                                newArmsPos   = armsPositionR;
                                newAnimationFixedDirection = Vector2.right;
                            }
                            else
                            {
                                newAnimState = AnimationsStates.BlockWalkLeft;
                                newArmsPos   = armsPositionL;
                                newAnimationFixedDirection = Vector2.left;
                            }
                        }
                        else
                        {
                            if (aim.y > 0)
                            {
                                newAnimState = AnimationsStates.BlockWalkDown;
                                newArmsPos   = armsPositionD;
                                newAnimationFixedDirection = Vector2.down;
                            }
                            else
                            {
                                newAnimState = AnimationsStates.BlockWalkUp;
                                newArmsPos   = armsPositionU;
                                newAnimationFixedDirection = Vector2.up;
                            }
                        }
                        UnlockAnimations();
                        PlayAnimation(newAnimState, true);
                        SetArmsAnimationDirection(newAnimationFixedDirection);
                        if (character.blocking)
                        {
                            PlayArmsAnimation(newAnimState);
                            if ((character.weapon) && (character.weapon.weaponAnimator))
                            {
                                //character.weapon.weaponAnimator.Play (newAnimState.ToString());
                                if ((character.weapon.weaponAnimator.speed == 1f) ||
                                    (resetWeaponAnim))
                                {
                                    character.weapon.weaponAnimator.Play("");
                                    character.weapon.weaponAnimator.Play(AnimationsStates.Block.ToString());
                                    //idle and block is the same animation, only speed is different
                                    character.weapon.weaponAnimator.speed = 5f;
                                    resetWeaponAnim = false;
                                }
                            }
                        }
                        else if (character.aiming)
                        {
                            armsTransform.localPosition = newArmsPos;
                            if (character.gun)
                            {
                                armsTransform.localPosition = newArmsPos;
                                character.gun.SetDirection(aim);
                            }
                        }
                    }
                    else
                    {
                        UnlockAnimations();
                        PlayAnimation(AnimationsStates.Block, true);
                        if (character.blocking)
                        {
                            PlayArmsAnimation(AnimationsStates.Block);
                            if ((character.weapon) && (character.weapon.weaponAnimator))
                            {
                                if ((character.weapon.weaponAnimator.speed == 5f) ||
                                    (resetWeaponAnim))
                                {
                                    character.weapon.weaponAnimator.Play("");
                                    character.weapon.weaponAnimator.Play(AnimationsStates.Block.ToString());
                                    //idle and block is the same animation, only speed is different
                                    character.weapon.weaponAnimator.speed = 1f;
                                    resetWeaponAnim = false;
                                }
                            }
                            SetArmsAnimationDirection(lastInputMove);
                        }
                        else if (character.aiming)
                        {
                            if (character.gun)
                            {
                                character.gun.SetDirection(aim);
                            }
                            if (Mathf.Abs(lastInputMove.x) > Mathf.Abs(lastInputMove.y))
                            {
                                if (lastInputMove.x > 0)
                                {
                                    SetArmsAnimationDirection(Vector2.right);
                                    armsTransform.localPosition = armsPositionR;
                                }
                                else
                                {
                                    SetArmsAnimationDirection(Vector2.left);
                                    armsTransform.localPosition = armsPositionL;
                                }
                            }
                            else
                            {
                                if (lastInputMove.y > 0)
                                {
                                    SetArmsAnimationDirection(Vector2.down);
                                    armsTransform.localPosition = armsPositionD;
                                }
                                else
                                {
                                    SetArmsAnimationDirection(Vector2.up);
                                    armsTransform.localPosition = armsPositionU;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if ((character.weapon) && (character.weapon.weaponAnimator))
                    {
                        character.weapon.weaponAnimator.speed = 1f;
                        resetWeaponAnim = true;
                    }
                    currentSpeed = runSpeed;
                }
            }
            if (topDownPhysics.rising)
            {
                PlayAnimation(AnimationsStates.Jump);
            }
            else if (topDownPhysics.falling)
            {
                PlayAnimation(AnimationsStates.Fall);
            }
            else if (move.magnitude > 0.01f)
            {
                PlayAnimation(AnimationsStates.Run);
                if (afterDash)
                {
                    EndDashAnim();
                }
            }
            else
            {
                if (!afterDash)
                {
                    PlayAnimation(AnimationsStates.Idle);
                }
            }
            SetAnimationDirection(lastInputMove);
            if (decreaseVelocity > 0)
            {
                decreaseVelocity = 0;
            }
            moveVelocity = move.normalized * currentSpeed;
        }
    }