/// <summary> /// Sets the state of the Player /// </summary> /// <param name="state">Which state to set</param> /// <exception cref="ArgumentOutOfRangeException"></exception> public void SetState(PlayerStates state) { PlayerBaseState playerState; switch (state) { case PlayerStates.Shoot: playerState = new ShootingState(this); break; case PlayerStates.Walking: playerState = new WalkingState(this); break; case PlayerStates.Talking: playerState = new TalkingState(this); break; case PlayerStates.Win: playerState = new WinState(this); break; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } _currentState?.ExitState(); _currentState = playerState; _currentState.EnterState(); }
protected void SwitchState(PlayerBaseState newState) { // current state exits state ExitState(); // new state enters state newState.EnterState(); _ctx.CurrentState = newState; }
private void EnableNewState(PlayerBaseState state) { currentState = state; currentState.EnterState(this); //currentState.playerStateManager.gameObject.SetActive(true); currentState.playerStateManager.EnableCharacter(currentState.playerStateManager.gameObject); ShadeWhite(currentState.playerStateManager.spriteRenderer); coroutine = WaitAndRevert(); StartCoroutine(coroutine); }
private void OnTriggerEnter2D(Collider2D collision) { //Debug.Log("Player hit collider: " + collision.gameObject.name); //if we hit spikes, change, update state and enter death state if (collision.gameObject.CompareTag("Spikes")) { _currentState = _states.Death(); _currentState.EnterState(); } }
public void TransitionToState(PlayerBaseState state) { if (freezePlayerState) { return; } currentState = state; currentState.EnterState(this); IfDebugPrintStates(); }
protected void SwitchState(PlayerBaseState newState) { ExitStates(); newState.EnterState(); if (isRootState) { context.RootState = newState; } else if (currentSuperState != null) { currentSuperState.PassOnSubState(newState); } }
public void TransitionToStateInstantly(PlayerBaseState state) { rb.gravityScale = DefaultGravityScale; animFinished = false; if (currentState != null) { currentState.playerStateManager.DisableCharacter(currentState.playerStateManager.gameObject); } currentState = state; currentState.EnterState(this); currentState.playerStateManager.EnableCharacter(currentState.playerStateManager.gameObject); }
public void TransitionToState(PlayerBaseState state) { if (isDying) { return; } currentState = state; currentState.EnterState(this); if (printDebugStates) { debugState = GetStateName(); Debug.Log(debugState); } }
protected void SetSubState(PlayerBaseState newSubState) { if (currentSubState != null) { currentSubState.ExitStates(); } if (newSubState == null) { currentSubState = null; } else { newSubState.EnterState(); newSubState.SetSuperState(this); currentSubState = newSubState; } }
//public bool IsFalling { get { return _isFalling; } } #endregion void Awake() { _playerControls = new PlayerControls(); _rb = GetComponent <Rigidbody2D>(); _anim = GetComponent <Animator>(); ledgeInfo = GetComponent <LedgeInformation>(); audioManager = FindObjectOfType <AudioManager>(); ragdoll = FindObjectOfType <RagdollController>(); interact = GetComponent <Interact>(); //camera test camManager = FindObjectOfType <CameraManager>(); //Controls calling OnMovement Input Function _playerControls.Gameplay.Move.started += OnMovementInput; _playerControls.Gameplay.Move.canceled += OnMovementInput; _playerControls.Gameplay.Move.performed += OnMovementInput; //_playerControls.Gameplay.Jump.started += OnJump; //Default //_playerControls.Gameplay.Jump.canceled += OnJump; //Default _playerControls.Gameplay.Jump.started += ctx => OnJump(); _playerControls.Gameplay.Jump.canceled += ctx => OnJumpReleased(); _playerControls.Gameplay.Jetpack.performed += ctx => Thrust(); _playerControls.Gameplay.Jetpack.canceled += ctx => ThrustReleased(); //Converting strings to hash is more performant _isGroundedHash = Animator.StringToHash("isGrounded"); _isRunningHash = Animator.StringToHash("isRunning"); _isFallingHash = Animator.StringToHash("isFalling"); _jumpHash = Animator.StringToHash("Jump"); //speedXHash = Animator.StringToHash("SpeedX"); // setup state _states = new PlayerStateFactory(this); // passes this PlayerStateMachine instance. PlayerStateFactory is expecting a PlayerStateMachine _currentState = _states.Idle(); _currentState.EnterState(); }
public void TransitionToState(PlayerBaseState state) { currentState = state; currentState.EnterState(this); }
public void TransitionToState(PlayerBaseState state) { //Store and set current concrete state currentState = state; //set the state as the current state currentState.EnterState(this); //Activate the EnterState function of a new state for player avatar when a transition is triggered }
public void TransitionToState(PlayerBaseState newState) { currentState = newState; PlayerEvents.CallPlayerChangedState(currentState); currentState.EnterState(this); }