Esempio n. 1
0
    public virtual void Start()
    {
        RefRigidbody = GetComponent <Rigidbody>();
        RefSphere    = GetComponent <SphereCollider>();
        Neighbors    = new List <Agent>();
        FSM          = new StateMachine.StateMachine();



        InitialState initial = new InitialState(this);
        GroupState   group   = new GroupState(this);
        ExitState    exit    = new ExitState(this);

        JoinGroupTransition JG = new JoinGroupTransition();

        JG.SetTargetState(group);
        ExitTriggerTransition ET = new ExitTriggerTransition();

        ET.SetTargetState(exit);
        ExitFormationTransition EF = new ExitFormationTransition();

        EF.SetTargetState(group);

        initial.AddTransitions(JG);
        group.AddTransitions(ET);
        exit.AddTransitions(EF);

        FSM.AddState(initial);
        FSM.AddState(group);
        FSM.AddState(exit);

        FSM.Start(initial);
    }
Esempio n. 2
0
 private void Awake()
 {
     myTransform    = transform;
     myRigidBody    = gameObject.GetComponent <Rigidbody2D>();
     myAnimator     = gameObject.GetComponent <Animator>();
     myStateMachine = gameObject.GetComponent <StateMachine.StateMachine>();
     gravity        = DefaulGravity;
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            List<IState> programStates = new List<IState>() { new State1(), new State2() };
            StateMachine stateManager = new StateMachine(programStates);

            stateManager.ChangeState(StateMachine.MACHINE_STATE.State1);

            if (Console.ReadKey().Key == ConsoleKey.E)
                stateManager.ChangeState(StateMachine.MACHINE_STATE.State2);

            Console.Read();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            StateMachine<States> machine = new StateMachine<States>();
            StateMachineCallbacks callbacks = new StateMachineCallbacks();

            machine.AddState(States.R);
            machine.AddState(States.G);
            machine.AddState(States.B);

            machine.AddTransition(States.R, States.G);
            machine.AddTransition(States.R, States.B);
            machine.AddTransition(States.G, States.R);
            machine.AddTransition(States.G, States.B);
            machine.AddTransition(States.B, States.R);
            machine.AddTransition(States.B, States.G);

            machine.AddEnterStateCallback(States.R, callbacks.EnteringState);
            machine.AddEnterStateCallback(States.G, callbacks.EnteringState);
            machine.AddEnterStateCallback(States.B, callbacks.EnteringState);

            machine.AddExitStateCallback(States.R, callbacks.ExitingState);
            machine.AddExitStateCallback(States.G, callbacks.ExitingState);
            machine.AddExitStateCallback(States.B, callbacks.ExitingState);

            machine.AddTransitionCallback(States.R, States.G, callbacks.Transition);
            machine.AddTransitionCallback(States.R, States.B, callbacks.Transition);
            machine.AddTransitionCallback(States.G, States.R, callbacks.Transition);
            machine.AddTransitionCallback(States.G, States.B, callbacks.Transition);
            machine.AddTransitionCallback(States.B, States.R, callbacks.Transition);
            machine.AddTransitionCallback(States.B, States.G, callbacks.Transition);

            machine.Transiting += new EventHandler<TransitingEventArgs<States>>(callbacks.TransitingEventHandler);
            machine.Transited += new EventHandler<TransitedEventArgs<States>>(callbacks.TransitedEventHandler);

            try
            {
                machine.GoToState(States.R);
                machine.GoToState(States.G);
                machine.GoToState(States.B);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex.Message);
            }

            Console.ReadLine();
        }
Esempio n. 5
0
        public bool Start(HostControl theHostControl)
        {
            rabbitMQHostUrl      = ConfigurationManager.AppSettings["RabbitMQHost"];
            rabbitMQUsername     = ConfigurationManager.AppSettings["RabbitMQUsername"];
            rabbitMQPassword     = ConfigurationManager.AppSettings["RabbitMQPassword"];
            changeStateQueueName = ConfigurationManager.AppSettings["changestatequeuename"];


            theLogWriter.Info($"Creating Service {nameof(StateMachineService)}...");

            DelegateSagaDbContextFactory <StateInstance> delegateSagaDbContextFactory =
                new DelegateSagaDbContextFactory <StateInstance>(() => new MachineSagaDBContext("defaultDatabase"));

            theStateInstance = new EntityFrameworkSagaRepository <StateInstance>(delegateSagaDbContextFactory, System.Data.IsolationLevel.ReadCommitted);

            theBusControl = Bus.Factory.CreateUsingRabbitMq(cfg =>
            {
                IRabbitMqHost theRabbitHost = cfg.Host(new Uri(rabbitMQHostUrl), host =>
                {
                    host.Username(rabbitMQUsername);
                    host.Username(rabbitMQPassword);
                });

                //EndpointConvention.Map<AssignCarrierToOrder>(new Uri(string.Concat(rabbitMQHostUrl, "Here is the queue")));

                cfg.ReceiveEndpoint(changeStateQueueName, e =>
                {
                    e.PrefetchCount = 16;
                    e.UseInMemoryOutbox();

                    var machine = new StateMachine.StateMachine();
                    e.StateMachineSaga(machine, theStateInstance);
                });
            });

            theLogWriter.Info($"Service {nameof(StateMachineService)} created and ready to flight :D");
            theBusControl.Start();
            return(true);
        }
Esempio n. 6
0
 public State(StateMachine fsm)
 {
     m_fsm = fsm;
 }
Esempio n. 7
0
 void Awake()
 {
     mStateMachine = new StateMachine.StateMachine <StateMachine.State>();
 }
Esempio n. 8
0
 public void Setup()
 {
     _directionManager = new DirectionManager();
     stateMachine      = new StateMachine.StateMachine(_directionManager);
 }
Esempio n. 9
0
 public RootState(StateMachine _StateMachine) => StateMachine = _StateMachine;