static void Main(string[] args) { BaseFSM.FSM <StatesID> fsm = new BaseFSM.FSM <StatesID>("Main"); /*************/ //Main SwitchState stateOne = new SwitchState(StatesID.ONE) { isStart = true }; stateOne.DefaultExit() .AddExitTransition(fsm, StatesID.FOUR); stateOne.AddTestExit(() => condition) .AddExitTransition(fsm, StatesID.TWO); SwitchState stateTwo = new SwitchState(StatesID.TWO); stateTwo.DefaultExit() .AddExitTransition(fsm, StatesID.FOUR); stateTwo.AddTestExit(() => condition) .AddExitTransition(fsm, StatesID.THREE); StableState stateThree = new StableState(StatesID.THREE); stateThree.AddAction("DoA", (o) => !condition, (o) => System.Console.WriteLine("action a")) .AddExitTransition(fsm, StatesID.ONE); stateThree.AddAction("DoB", (o) => condition, (o) => System.Console.WriteLine("action b")) .AddExitTransition(fsm, StatesID.FOUR); StateWithFSM stateFour = new StateWithFSM(StatesID.FOUR); stateFour.SubFSMExit() .AddExitTransition(fsm, StatesID.THREE); ///////////// BaseFSM.Cursor <StatesID> cursor = fsm.GetCursor(); System.Console.WriteLine(cursor); fsm.Start(); System.Console.WriteLine(cursor); if (cursor.curState.id == StatesID.THREE) { cursor.DoAction("DoA"); } System.Console.WriteLine(cursor); if (cursor.curState.id == StatesID.SUB_ONE) { cursor.DoAction("DoSubA"); } System.Console.WriteLine(cursor); }
public override void LoadFSM() { BaseFSM.FSM <StatesID> subFsm = new BaseFSM.FSM <StatesID>("Sub"); subFsm.OnFinish += (x, y) => { System.Console.WriteLine("*** subFSM onFinish()"); }; SetSubFSM(subFsm); StableState stateSubOne = new StableState(StatesID.SUB_ONE) { isStart = true }; stateSubOne.AddAction("DoSubA", (o) => true, (o) => System.Console.WriteLine("sub action a")) .AddExitTransition(subFsm, StatesID.SUB_TWO); SwitchState stateSubTwo = new SwitchState(StatesID.SUB_TWO) { isFinish = true }; subFsm.AddState(stateSubTwo); }
FSM <STATE_ID> fsm; //todo убрать! есть в стеке public Cursor(FSM <STATE_ID> fsm) { this.fsm = fsm; SetCursor(); }
public void AddExitTransition(FSM <STATE_ID> fsm, STATE_ID nextState) { fsm.AddStateExit(state, exitId, nextState); }
public void OnSubFSMFinish(FSM <STATE_ID> fsm, STATE_ID state_id) { subFsm.OnFinish -= OnSubFSMFinish; DoExitState(subFSMExitID); }
public void SetSubFSM(FSM <STATE_ID> subFsm) { this.subFsm = subFsm; subFsm.OnFinish += OnSubFSMFinish; }