private IEnumerator WaitAndDisable(PlayerBaseState newState) { yield return(new WaitForSeconds(.1f)); currentState.playerStateManager.DisableCharacter(currentState.playerStateManager.gameObject); EnableNewState(newState); }
public static void CallPlayerChangedState(PlayerBaseState newPlayerState) { if (PlayerChangedState != null) { PlayerChangedState(newPlayerState); } }
private void ChangeStateIfNotNull(PlayerBaseState newState) { if (newState != null) { ChangeState(newState); } }
void ShowState(PlayerBaseState state) { if (state.GetType() == typeof(PlayerIdleState)) { setButtonDown(IdleImage); setButtonUp(JumpingImage); setButtonUp(DuckingImage); setButtonUp(SpinningImage); } else if (state.GetType() == typeof(PlayerJumpingState)) { setButtonUp(IdleImage); setButtonDown(JumpingImage); setButtonUp(DuckingImage); setButtonUp(SpinningImage); } else if (state.GetType() == typeof(PlayerDuckingState)) { setButtonUp(IdleImage); setButtonUp(JumpingImage); setButtonDown(DuckingImage); setButtonUp(SpinningImage); } else if (state.GetType() == typeof(PlayerSpinningState)) { setButtonUp(IdleImage); setButtonUp(JumpingImage); setButtonUp(DuckingImage); setButtonDown(SpinningImage); } }
public virtual PlayerBaseState TakeDamage(float damage, PlayerBaseState nextStateIfDamaged = null, bool whiteBlink = true) { if (rsc.debugMng.godMode || bb.isInvulnerable) { return(null); } bb.blinkController.BlinkWhiteOnce(); bb.currentHealth -= damage; if (bb.currentHealth <= 0) { bb.currentHealth = 0; } //Send event PlayerDamagedEventInfo.eventInfo.damage = damage; PlayerDamagedEventInfo.eventInfo.currentHealth = bb.currentHealth; rsc.eventMng.TriggerEvent(EventManager.EventType.PLAYER_DAMAGED, PlayerDamagedEventInfo.eventInfo); if (bb.currentHealth == 0) { return(bb.dyingState); } else { bb.player.Damaged(); return(nextStateIfDamaged); } }
protected void NewRoot(PlayerBaseState newrootState) { context.RootState.ExitStates(); context.RootState = newrootState; context.RootState.EnterState(); context.RootChanged = true; }
/// <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(); }
private void SwitchToNewState(Type nextState) { currState.Exit(); currState = availableStates[nextState]; currState.Enter(); OnStateChanged?.Invoke(currState); //?? }
public void Switch <T>() where T : PlayerBaseState { var state = _allStates.Find(s => s is T); _currentState.Stop(); _currentState = state; _currentState.Start(); }
public PlayerFacade(Animator at, Rigidbody2D rig, Transform trs) { this.trs = trs; this.rig = rig; _state = new PlayerIdleState(this); _inputQueue = new InputQueue(); anim = at; }
// Start is called before the first frame update void Start() { rb = GetComponent <Rigidbody2D>(); MouseLook = GetComponent <PlayerMouseLook>(); currentState = airState; StartCoroutine(DecreaseHealthRoutine()); }
public void TransitionToStateDelayed(PlayerBaseState state) { if (CheckIfCanTransitionToState(state)) { rb.gravityScale = DefaultGravityScale; animFinished = false; DisableOldState(state); } }
public void ChangeState(PlayerBaseState newState) { if (currentState != null) { currentState.Exit(); } newState.Enter(); currentState = newState; }
public string PrintHirarchy(PlayerBaseState state) { if (state.currentSubState != null) { return(state.ToString() + " > " + PrintHirarchy(state.currentSubState)); } return(state.ToString()); }
protected void SwitchState(PlayerBaseState newState) { // current state exits state ExitState(); // new state enters state newState.EnterState(); _ctx.CurrentState = newState; }
private void DisableOldState(PlayerBaseState newState) { if (currentState != null) { playerExpression.gameObject.SetActive(false); ShadeWhite(currentState.playerStateManager.spriteRenderer); coroutine = WaitAndDisable(newState); 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 (currentState != null) { currentState.Exit(this); } currentState = state; currentState.Enter(this); }
private void CheckPlayerState(PlayerBaseState newState) { if (!playerController.isUsing) { Time.timeScale = 1f; } else if (playerController.isUsing) { Time.timeScale = 0f; } }
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); }
public bool CheckIfCanTransitionToState(PlayerBaseState state) { bool result = false; if (_unlockableTracker.IsCharacterUnlocked(state.GetType())) { result = true; } return(result); }
public virtual PlayerBaseState InfectionReceived(float damage) { if (rsc.debugMng.godMode || bb.isInvulnerable) { return(null); } PlayerBaseState result = TakeDamage(damage, bb.receivingDamageState, true); bb.player.StartCoroutine(HandleInvulnerabilityTime()); return(result); }
public void TransitionToState(PlayerBaseState state) { if (freezePlayerState) { return; } currentState = state; currentState.EnterState(this); IfDebugPrintStates(); }
private void ChangeState(PlayerBaseState newState) { if (currentState != null) { //Debug.Log("Player " + playerId + " Exiting: " + currentState.GetType().Name); currentState.OnStateExit(); } currentState = newState; if (currentState != null) { //Debug.Log("Player " + playerId + " Entering: " + currentState.GetType().Name); currentState.OnStateEnter(); } }
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 SetCurrentState(StateIndex stateIndex) { if (m_currentState != null) { m_currentState.OnExit(); } m_currentState = m_states[stateIndex]; if (m_currentState != null) { m_currentState.OnEnter(); } }
public void SetState(PlayerBaseState newState) { if (currentState != null) { currentState.OnStateExit(); } currentState = newState; if (currentState != null) { currentState.OnStateEnter(); } }
private void Update() { if (currState == null) { currState = availableStates.Values.First(); //first state is default } var nextState = currState?.Tick(); if (nextState != null && nextState != currState?.GetType()) { SwitchToNewState(nextState); } }
protected void SwitchState(PlayerBaseState newState) { ExitStates(); newState.EnterState(); if (isRootState) { context.RootState = newState; } else if (currentSuperState != null) { currentSuperState.PassOnSubState(newState); } }
public virtual PlayerBaseState InfectionReceived(float damage, Vector3 origin, Vector2 infectionForces) { if (rsc.debugMng.godMode || bb.isInvulnerable) { return(null); } bb.infectionOrigin = origin; bb.infectionForces = infectionForces; PlayerBaseState result = TakeDamage(damage, bb.pushedState, true); bb.player.StartCoroutine(HandleInvulnerabilityTime()); return(result); }
public void Spawn() { currentState = spawningState; currentState.OnStateEnter(); }
//Unity methods void Awake() { Debug.Log("Player " + playerId + " created."); rend = GetComponentInChildren<Renderer>(); ctrl = GetComponent<CharacterController>(); voxelization = GetComponent<VoxelizationClient>(); spawningState = new PlayerSpawningState(); idleState = new PlayerIdleState(); longIdleState = new PlayerLongIdleState(); movingState = new PlayerMovingState(); dashingState = new PlayerDashingState(); specialState = new PlayerSpecialState(); swingingState = new PlayerSwingingState(); receivingDamageState = new PlayerReceivingDamageState(); fallingState = new PlayerFallingState(); dyingState = new PlayerDyingState(); spawningState.Init(this); idleState.Init(this); longIdleState.Init(this); movingState.Init(this); dashingState.Init(this); specialState.Init(this); swingingState.Init(this); receivingDamageState.Init(this); fallingState.Init(this); dyingState.Init(this); currentState = spawningState; string player = ""; switch (playerId) { case 1: player = "P1"; break; case 2: player = "P2"; break; } moveHorizontal = player + "_Horizontal"; moveVertical = player + "_Vertical"; aimHorizontal = player + "_AimHorizontal"; aimVertical = player + "_AimVertical"; fire = player + "_Fire"; dash = player + "_Dash"; special = player + "_Special"; playerRayCastMask = LayerMask.GetMask(player + "RayCast"); animator = GetComponent<Animator>(); }
private void ChangeState(PlayerBaseState newState) { if (currentState != null) currentState.OnStateExit(); currentState = newState; if (currentState != null) currentState.OnStateEnter(); }