Exemple #1
0
    private void CreateFiniteStateMachine()
    {
        stateMachine = new StateMachineEngine(false);

        arriveToHouse = stateMachine.CreatePerception <ArriveToDestination>(new ArriveToDestination());
        arriveToHouse.SetDestination(housePoint.position);
        ValuePerception enemyNear = stateMachine.CreatePerception <ValuePerception>(() => Vector3.Distance(transform.position, badBoy.transform.position) < 8);
        BehaviourTreeStatusPerception enterTheHouse = stateMachine.CreatePerception <BehaviourTreeStatusPerception>(behaviourTree, ReturnValues.Succeed);

        pointToRun = stateMachine.CreatePerception <ArriveToDestination>(new ArriveToDestination());

        State goToHouse        = stateMachine.CreateEntryState("Go to house", ToHouse);
        State subBehaviourTree = stateMachine.CreateSubStateMachine("Sub behaviour tree", behaviourTree);
        State runAway          = stateMachine.CreateState("Run away", RunAway);
        State enterHouse       = stateMachine.CreateState("Enter in house", EnterHouse);

        stateMachine.CreateTransition("To enter the house", goToHouse, arriveToHouse, subBehaviourTree);
        stateMachine.CreateTransition("To run away", goToHouse, enemyNear, runAway);
        behaviourTree.CreateExitTransition("Run away", subBehaviourTree, enemyNear, runAway);
        behaviourTree.CreateExitTransition("Enter the house", subBehaviourTree, enterTheHouse, enterHouse);
        stateMachine.CreateTransition("Stop running", runAway, pointToRun, goToHouse);
    }
Exemple #2
0
    private void CreateStateMachine()
    {
        radarFSM = new StateMachineEngine(false);

        // Perceptions
        Perception direct    = radarFSM.CreatePerception <PushPerception>();
        Perception breakDown = radarFSM.CreatePerception <TimerPerception>(30);
        Perception fix       = radarFSM.CreatePerception <TimerPerception>(15);

        // States
        State entryState   = radarFSM.CreateEntryState("Entry State");
        State workingState = radarFSM.CreateSubStateMachine("Working", workingSubFSM);

        brokenState = radarFSM.CreateState("Broken", Broken);

        // Transitions
        radarFSM.CreateTransition("Direct", entryState, direct, workingState);
        workingSubFSM.CreateExitTransition("To broken", workingState, breakDown, brokenState);
        radarFSM.CreateTransition("To working", brokenState, fix, workingState);

        radarFSM.Fire("Direct");
    }