public StateResult Process(float time) { if (!_running) { return(null); } if (_currentStateCode == null) { return(null); } if (!_states.ContainsKey(_currentStateCode.NextStateCode)) { _currentStateCode.Result = StateResult.StateNotFound; return(_currentStateCode); } var state = _states[_currentStateCode.NextStateCode]; if (state == null) { _currentStateCode.Result = StateResult.StateNotFound; return(_currentStateCode); } if (!state.IsStarted()) { MyLog.DebugWithFrame(_name, string.Format("Start state: {0}", state.GetStateName())); _currentStateCode.Result = StateResult.Started; state.Start(); state.Initialize(_data, time); } if (state.IsAbort()) { MyLog.DebugWithFrame(_name, string.Format("Abort state: {0}", state.GetStateName())); _currentStateCode.Result = StateResult.Aborted; return(_currentStateCode); } var finish = state.Process(_data, time); if (state.IsAbort()) { MyLog.DebugWithFrame(_name, string.Format("Abort state: {0}", state.GetStateName())); _currentStateCode.Result = StateResult.Aborted; return(_currentStateCode); } if (finish) { MyLog.DebugWithFrame(_name, string.Format("Finish state: {0}", state.GetStateName())); _currentStateCode = state.Finish(_data, time); state.Reset(); } return(_currentStateCode); }
public void SwitchTo(int code) { if (_currentStateCode == null) { _currentStateCode = new StateResult(); _currentStateCode.Result = StateResult.Null; _currentStateCode.NextStateCode = code; Reset(); return; } if (_currentStateCode.NextStateCode == code) { return; } _currentStateCode.Result = StateResult.Null; _currentStateCode.NextStateCode = code; Reset(); }