public bool SwitchState(T newState) { OnStateFinish?.Invoke(CurrentState, newState); CurrentState = newState; OnStateStart?.Invoke(CurrentState, newState); return(true); }
public void AddState(StateBase state) { var stateType = state.GetType(); Debug.Assert(!States.ContainsKey(stateType)); States.Add(stateType, state); state.Initialize(Context); state.OnEnter += (enterState) => { OnStateEnter?.Invoke(enterState); }; state.OnFinish += (finishState) => { OnStateFinish?.Invoke(finishState); }; }
public void ExitStateCallback(T owner) { // If we have states queued, enter the next state on that list if (StateQueue.Count > 0) { State <T> state = StateQueue[0]; StateQueue.RemoveAt(0); UpdateStateHistory(); currentState = null; ChangeState(state); } // If we don't have states queued trigger the OnStateFinish event that the owner can react to else if (OnStateFinish != null) { UpdateStateHistory(); currentState = null; OnStateFinish?.Invoke(); } }
protected virtual void Finish() => OnStateFinish?.Invoke(this);