/// <summary> /// Change state /// </summary> /// <param name="newState">State to go</param> public void Go(AState newState) { if (newState == null) { return; } Log.Info($"FSM:Go({newState})"); currentState?.Exit(); currentState = newState; currentState.Enter(); }
public void ChangeState(string newState, float delayBetweenState = 0) { if (newState == null) { _activeState.Exit(); _activeState = null; return; } _activeState.Exit(); _activeState = FindState(newState); if (delayBetweenState == 0) { _activeState.Enter(); } else { Timer.Add(delayBetweenState, _activeState.Enter); } Debug.Log("Current Game State - " + _activeState); }
public void Update() { AState currentState = Top(StateStack); if (currentState != null) { currentState.Update(); if (currentState.IsComplete) { currentState.Exit(); StateStack = StateStack.Where(x => !x.IsComplete).ToList(); /* We don't enter in the same loop as an exit, or the states may conflict. */ currentState = Top(StateStack); WaitingToFinish = currentState == null; } } }