コード例 #1
0
                public void It_should_restart_nested_fsm_on_rerun()
                {
                    var nestedFsm = new FsmBuilder()
                                    .Default(StateId.A)
                                    .State(StateId.A, (state) => {
                        state.SetTransition("next", StateId.B);
                        state.Update((action) => action.Transition("next"));
                    })
                                    .State(StateId.B, (state) => {
                        state.FsmExit();
                    })
                                    .Build();

                    var fsm = new FsmBuilder()
                              .Default(StateId.A)
                              .State(StateId.A, (state) => {
                        state.SetTransition("next", StateId.B);
                        state.RunFsm("next", nestedFsm);
                    })
                              .State(StateId.B, (state) => {
                        state.RunFsm("none", nestedFsm);
                    })
                              .Build();

                    fsm.Tick();
                    fsm.Tick();

                    Assert.AreEqual(StateId.A, nestedFsm.CurrentState.Id);
                }
コード例 #2
0
        public void It_should_call_the_extension_method_from_the_StateBuilder_class()
        {
            var fsmBuilder = new FsmBuilder()
                             .State(StateId.A, (state) => {
                state
                .MyCustomStateBuilderMethod()
                .Update((action) => { });
            });

            fsmBuilder.Build();
        }
コード例 #3
0
                public void It_should_call_Enter_on_nested_FSM_when_created()
                {
                    var stateEnter = false;
                    var nestedFsm  = new FsmBuilder()
                                     .Default(StateId.A)
                                     .State(StateId.A, (state) => {
                        state.Enter((action) => stateEnter = true);
                    })
                                     .Build();

                    new FsmBuilder()
                    .Default(StateId.A)
                    .State(StateId.A, (state) => {
                        state.RunFsm("a", nestedFsm);
                    })
                    .Build();

                    Assert.IsTrue(stateEnter);
                }
コード例 #4
0
ファイル: Program.cs プロジェクト: mustaddon/StateMachine
        static async Task Main(string[] args)
        {
            var fsm = new FsmBuilder <State, Event>(State.S1)
                      .OnJump(x => Console.WriteLine($"On jump to {x.Fsm.Current} from {x.PrevState}"))
                      .OnReset(x => Console.WriteLine($"On reset to {x.Fsm.Current} from {x.PrevState}"))
                      .OnTrigger(x => Console.WriteLine($"On trigger {x.Event}"))
                      .OnError(x => Console.WriteLine($"On error {x.Fsm.Current}: {x.Message}"))
                      .OnEnter(x => Console.WriteLine($"Enter state {x.Fsm.Current} from {x.PrevState}"))
                      .OnExit(x => Console.WriteLine($"Exit state {x.Fsm.Current} to {x.NextState}"))
                      .On(Event.E0).Execute(x => "shared to all states")

                      .State(State.S1)
                      .On(Event.E1)
                      .Execute(async x =>
            {
                Console.WriteLine($"Execute {x.Fsm.Current}>{x.Event}");
                await Task.Delay(1000);
                return("some data");
            })

                      .On(Event.E2).JumpTo(State.S2)
                      .On(Event.E3).JumpTo(State.S3)
                      .State(State.S2)
                      .Enable(async x => { await Task.Delay(1000); return(true); })
                      .On(Event.E1).JumpTo(async x => { await Task.Delay(1000); return(State.S1); })
                      .State(State.S3)
                      .OnEnter(x => Console.WriteLine($"Final state"))
                      .Build();


            var events = new[] { Event.E1, Event.E2, Event.E0, Event.E1, Event.E3 };

            foreach (var e in events)
            {
                Console.WriteLine($"Current state: {fsm.Current}");
                Console.WriteLine($"Available events: {string.Join(", ", fsm.GetEvents())}");
                Console.WriteLine($"Result: {await fsm.TriggerAsync(e)}\n\n");
            }

            await fsm.ResetAsync();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: mustaddon/FsmWorkflow
        public IStateMachine <State, Action> Build(SomeObject obj)
        {
            var fsm = new FsmBuilder <State, Action>(obj.State)
                      .OnJump(x => obj.State  = x.Fsm.Current)
                      .OnReset(x => obj.State = x.Fsm.Current)
                      .State(State.S1)
                      .OnEnter(_consoleWrite)
                      .OnExit(_consoleWrite)
                      .On(Action.A1).Execute(x => { Console.WriteLine($"Execute {x.Fsm.Current}>{x.Event}"); return(obj.Title); })
                      .On(Action.A2).JumpTo(State.S2)
                      .On(Action.A3).JumpTo(State.S3)
                      .State(State.S2)
                      .OnEnter(_consoleWrite)
                      .OnExit(_consoleWrite)
                      .On(Action.A1).JumpTo(State.S1)
                      .State(State.S3)
                      .OnEnter(_consoleWrite)
                      .OnExit(_consoleWrite)
                      .Build();

            return(fsm);
        }
コード例 #6
0
 public static void AddFsmToSelected()
 {
     FsmBuilder.AddFsmToSelected();
     //PlayMakerFSM playmakerFSM = Selection.activeGameObject.AddComponent<PlayMakerFSM>();
     //FsmEditor.SelectFsm(playmakerFSM.Fsm);
 }
コード例 #7
0
 public void BeforeEach()
 {
     _owner   = new GameObject();
     _builder = new FsmBuilder().Owner(_owner);
 }
コード例 #8
0
            public void Should_not_crash_with_nothing_built()
            {
                var fsm = new FsmBuilder().Build();

                fsm.Tick();
            }