예제 #1
0
    private void CreateSubMachine()
    {
        workingSubFSM = new StateMachineEngine(true);

        // Perceptions
        detectCar = workingSubFSM.CreatePerception <DetectCar>(new DetectCar(gameObject, pointToLook));
        Perception carOverSpeed   = workingSubFSM.CreatePerception <ValuePerception>(() => detectCar.GetCarSpeed() > 20);
        Perception carOnSpeed     = workingSubFSM.CreatePerception <ValuePerception>(() => detectCar.GetCarSpeed() <= 20);
        Perception overSpeedLimit = workingSubFSM.CreateAndPerception <AndPerception>(detectCar, carOverSpeed);
        Perception onSpeedLimit   = workingSubFSM.CreateAndPerception <AndPerception>(detectCar, carOnSpeed);
        Perception timeout        = workingSubFSM.CreatePerception <TimerPerception>(2);

        // States
        State waitingForCarState = workingSubFSM.CreateEntryState("Waiting for car", OnWaitingForCar);
        State speedingState      = workingSubFSM.CreateState("Speeding", OnSpeeding);
        State correctSpeedState  = workingSubFSM.CreateState("Correct speed", OnCorrectSpeed);

        // Transitions
        workingSubFSM.CreateTransition("Car over speed limit", waitingForCarState, overSpeedLimit, speedingState);
        workingSubFSM.CreateTransition("Car on speed limit", waitingForCarState, onSpeedLimit, correctSpeedState);
        workingSubFSM.CreateTransition("To waiting for next bad car", speedingState, timeout, waitingForCarState);
        workingSubFSM.CreateTransition("To waiting for next good car", correctSpeedState, timeout, waitingForCarState);
    }