// Update is called once per frame void Update() { newState = currentState.DoState(this); if (currentState != newState) { //so if we DO change states. we will call Init, //then DoState will be called next frame. So dont have Init call DoState(); currentState = newState; currentState.InitState(this); } }
void SwitchState() { stateIndex++; if (stateIndex >= charStates.Count) stateIndex = 0; currentState = charStates[stateIndex]; if (currentState is LandState) spriteAnim.namePrefix = "grobo"; else spriteAnim.namePrefix = "romaid"; }
void Awake() { charStates.Add(new LandState()); charStates.Add(new AquaticState()); stateIndex = 0; currentState = charStates[stateIndex]; sprite.spriteName = "grobo1"; spawnSystem = GameObject.FindObjectOfType<CFX_SpawnSystem>(); OnValidate(); }
public CharacterStateMachine(PlayerController player) { _player = player; CharacterState.Init(player); PlayerIdleState idleState = new PlayerIdleState(); PlayerMoveState moveState = new PlayerMoveState(); PlayerAimState aimState = new PlayerAimState(); PlayerAttackingState attackState = new PlayerAttackingState(); idleState.InitTransitions(moveState, aimState); moveState.InitTransitions(idleState, attackState, aimState); aimState.InitTransitions(moveState, attackState, idleState); attackState.InitTransitions(moveState); _allStates.Add(idleState.GetType(), idleState); _allStates.Add(moveState.GetType(), moveState); _currentState = idleState; }
public virtual void Update() { foreach (var transition in _transitionToStates) { if (transition.GetType() == typeof(PlayerIdleState)) { idleState = transition; } Func <bool> Condition; if (transition.TransitionConditions.TryGetValue(GetType(), out Condition)) { if (Condition()) { ChangeState = transition; return; } } else { Debug.LogError("Transition Condition Doesn't exit for: " + GetType() + " to " + transition.GetType()); } } }
public virtual void OnEnter() { Debug.Log("Entered: " + GetType()); ChangeState = null; }
void Start() { currentState = idleInactiveState; currentState.InitState(this); }
private void ChangeState(ICharState newState) { _currentState?.OnExit(); _currentState = newState; _currentState.OnEnter(); }