public IStateMachine <TState, TAction> Build() { if (this.stateMoveInfoSearcher == null) { this.stateMoveInfoSearcher = new DefaultStateMoveInfoSearcher <TState, TAction>(this.stateMoveInfos); } if (!IsDefaultStateExists()) { this.startState = GetDefaultState(); } if (!IsDefaultStateExists()) { throw new CodeStateMachineBuilderBuildException("没有指定默认状态,无法构建"); } if (!IsStopStateExists()) { this.stopStateSet = new HashSet <TState>(GetStopStates()); } if (!IsStopStateExists()) { this.stopStateSet = new HashSet <TState>(); } return(new CodeStateMachine <TState, TAction>(this.stateMoveInfoSearcher, this.startState.Value, this.stopStateSet)); }
public CodeStateMachineBuilder <TState, TAction> Move(TState from, TAction action, TState to) { if (this.stateMoveInfoSearcher != null) { this.stateMoveInfoSearcher = null; } this.stateMoveInfos.Add(new StateMoveInfo <TState, TAction>(from, action, to)); return(this); }
public CodeStateMachine(IStateMoveInfoSearcher <TState, TAction> stateMoveInfoSearcher, TState startState, HashSet <TState> stopState) { this.stateMoveInfoSearcher = stateMoveInfoSearcher; this.currentState = startState; this.stopStates = stopState; }