public void SetNewState(CharacterStateBase newState) { if (mainMovementState == null || newState.GetType() != mainMovementState.GetType()) { if (mainMovementState != null) { exitState(mainMovementState); } enterState(newState); mainMovementState = newState; } }
void onStateChanged(CharacterStateBase newState, CharacterStateBase prevState) { if (typeof(InAirState).IsAssignableFrom(prevState.GetType()) && typeof(GroundState).IsAssignableFrom(newState.GetType())) { InAirState inAirState = (InAirState)prevState; if (Mathf.Abs(inAirState.LastInAirVelocity.y) > minYVelocityToAnimateLanding) { headAnimationController.AnimateLand(); } } if (typeof(WallRunState).IsAssignableFrom(newState.GetType())) { WallRunState wallRunState = (WallRunState)newState; switch (wallRunState.WallRunSide) { case WallRunState.WallRunType.LEFT: spineAnimationController.AnimateWallRunLeft(); break; case WallRunState.WallRunType.RIGH: spineAnimationController.AnimateWallRunRight(); break; } } if (typeof(WallRunState).IsAssignableFrom(prevState.GetType())) { spineAnimationController.AnimateToDefaultPosition(); } else if (typeof(GroundState).IsAssignableFrom(newState.GetType())) { GroundState groundState = (GroundState)newState; onGroundStateInternalStateChaged(groundState.InternalState); } else if (typeof(SlideState).IsAssignableFrom(newState.GetType())) { headAnimationController.SetCrouch(true); } }