protected override void HandleInput(HashSet <KeyPress> input) { if ((timeLeft -= Time.deltaTime) > 0f) { return; } if (input.Contains(KeyPress.MoveRight)) { ChangeState(PlayerStateEnum.TestMove); AnimatorCommon.FaceRight(_animator); timeLeft = Constants.ROLL_TIME; } else if (input.Contains(KeyPress.MoveLeft)) { ChangeState(PlayerStateEnum.TestMove); AnimatorCommon.FaceLeft(_animator); timeLeft = Constants.ROLL_TIME; } else { ChangeState(PlayerStateEnum.TestIdle); timeLeft = Constants.ROLL_TIME; } }
protected override void HandleInput(HashSet <KeyPress> input) { if (input.Contains(KeyPress.Roll)) { ChangeState(PlayerStateEnum.TestRoll); } else if (input.Contains(KeyPress.Jump) && IsGrounded()) { ChangeState(PlayerStateEnum.TestJump); } else if (input.Contains(KeyPress.MoveLeft)) { // unflipped = facing right ChangeState(PlayerStateEnum.TestMove); AnimatorCommon.FaceLeft(_animator); } else if (input.Contains(KeyPress.MoveRight)) { // unflipped = facing right ChangeState(PlayerStateEnum.TestMove); AnimatorCommon.FaceRight(_animator); } else if (input.Contains(KeyPress.MidAttack)) { ChangeState(PlayerStateEnum.TestMidAttack); } }
public void Update() { // ignore input until playing correct animation if (!PlayingNextAnimation() && !FinishedCurrentAnimation()) { return; } if (_playerInput != null && _playerInput.Count > 0 && !FinishedCurrentAnimation()) { HandleInput(_playerInput); } else if (_playerInputHandling && !FinishedCurrentAnimation()) { _playerInput = PlayerInput.GetInput(); } else if (_selfTransition) { AnimatorCommon.RestartCurrentAnimation(_animator); _selfTransition = false; } else { ChangeState(PlayerStateEnum.TestIdle); } }
protected override void HandleInput(HashSet <KeyPress> input) { if (!CollisionCommon.IsGrounded(_player)) { ChangeState(PlayerStateEnum.TestAirborneMove); } else if (input.Contains(KeyPress.Jump)) { ChangeState(PlayerStateEnum.TestJump); } else if (input.Contains(KeyPress.Roll)) { ChangeState(PlayerStateEnum.TestRoll); } else if (input.Contains(KeyPress.MidAttack)) { ChangeState(PlayerStateEnum.TestMidAttack); } else if (input.Contains(KeyPress.MoveRight)) { ChangeState(PlayerStateEnum.TestMove); AnimatorCommon.FaceRight(_animator); } else if (input.Contains(KeyPress.MoveLeft)) { ChangeState(PlayerStateEnum.TestMove); AnimatorCommon.FaceLeft(_animator); } }
protected bool PlayingNextAnimation() { // after _animator.SetInteger("state"), takes a few frames before actually changing animation // however, the int itself is changed // is _animator.GetInteger("state") the same as the one that's playing? return(GetStateHash(AnimatorCommon.GetState(_animator)) == GetCurrentStateHash()); }
void Start() { _animator = GetComponent <Animator>(); _spriteRenderer = GetComponent <SpriteRenderer>(); _states = new Dictionary <PlayerStateEnum, PlayerState>(); AnimatorCommon.FaceRight(_animator); AnimatorCommon.SetState(_animator, (int)(PlayerStateEnum.TestIdle)); InitStates(); }
protected float NormalizedTime() { return(AnimatorCommon.NormalizedTime(_animator)); }
protected void ChangeState(PlayerStateEnum newState) { _playerInput = null; _selfTransition = ((int)newState == AnimatorCommon.GetState(_animator)); AnimatorCommon.SetState(_animator, (int)newState); }
public PlayerStateEnum GetState() { return((PlayerStateEnum)AnimatorCommon.GetState(_animator)); }
private void FlipSpriteCorrectDirection() { AnimatorCommon.FlipSpriteCorrectDirection(_animator, _spriteRenderer); }
public bool FacingRight() { return(AnimatorCommon.FacingRight(_animator)); }