SimpleStateMachineTisStrict Property |
Namespace: KSPDev.ProcessingUtils
public bool isStrict { get; }
class SimpleStateMachineStrict { public enum State { One, Two, Three }; public void TestMachine() { var sm = new SimpleStateMachine<State>(strict: true); sm.SetTransitionConstraint(State.One, new State[] { State.Two }); sm.AddStateHandlers( State.One, enterHandler: newState => LogFromTo(sm.currentState, newState), leaveHandler: newState => LogFromTo(sm.currentState, newState)); sm.currentState = State.One; // Start the machine. // Logs: Move from NULL to One if (sm.CheckCanSwitchTo(State.Two)) { sm.currentState = State.Two; // An allowed tranistion. // Logs: Move from One to Two } if (sm.CheckCanSwitchTo(State.Three)) { // This will never happen. sm.currentState = State.Three; } sm.currentState = null; // Stop the machine. // Logs: Move Two to NULL } void LogFromTo(State? from, State? to) { Debug.LogFormat( "Move from {0} to {1}", DbgFormatter.Nullable(from), DbgFormatter.Nullable(to)); } }