Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        manager = new HFSMManagerSystem();

        HomeSystem homeSystem = new HomeSystem("HomeSystem", manager);

        ReadBookState readBookState = new ReadBookState("ReadBookState", homeSystem, systemText, stateText);

        readBookState.AddTransition("Cook", "CookState");
        CookState cookState = new CookState("CookState", homeSystem, systemText, stateText);

        cookState.AddTransition("Sleep", "SleepState");
        SleepState sleepState = new SleepState("SleepState", homeSystem, systemText, stateText);

        sleepState.AddTransition("ReadBook", "ReadBookState");

        homeSystem.AddState(readBookState);
        homeSystem.AddState(cookState);
        homeSystem.AddState(sleepState);

        MarketSystem marketSystem = new MarketSystem("MarketSystem", manager);

        BuyState buyState = new BuyState("BuyState", marketSystem, systemText, stateText);

        buyState.AddTransition("Pay", "PayState");
        PayState payState = new PayState("PayState", marketSystem, systemText, stateText);

        payState.AddTransition("Buy", "BuyState");

        marketSystem.AddState(buyState);
        marketSystem.AddState(payState);

        manager.AddSubSystem(homeSystem);
        manager.AddSubSystem(marketSystem);
    }
Example #2
0
    void InitFSM()
    {
        fsm = new FSMSystem();
        FSMState sleepState = new SleepState(fsm);

        sleepState.AddTransition(Transition.Open, StateID.Idle);


        FSMState IdleState = new IdleState(fsm);

        IdleState.AddTransition(Transition.Close, StateID.Sleep);
        IdleState.AddTransition(Transition.SeePlayer, StateID.Patrol);
        IdleState.AddTransition(Transition.Shopping, StateID.GoOut);
        IdleState.AddTransition(Transition.StartPlay, StateID.Play);

        FSMState patrolState = new PatrolState(fsm);

        patrolState.AddTransition(Transition.Open, StateID.Idle);
        patrolState.AddTransition(Transition.SeePlayer, StateID.Chase);


        FSMState chaseState = new ChaseState(fsm);

        chaseState.AddTransition(Transition.LostPlayer, StateID.Patrol);
        chaseState.AddTransition(Transition.FindEnemy, StateID.Bark);

        FSMState barkState = new BarkState(fsm);

        barkState.AddTransition(Transition.LostPlayer, StateID.Patrol);

        FSMState gooutState = new GoOutState(fsm);

        gooutState.AddTransition(Transition.Back, StateID.ComeBack);
        gooutState.AddTransition(Transition.SeePlayer, StateID.Patrol);

        FSMState comebackState = new ComeBackState(fsm);

        comebackState.AddTransition(Transition.Open, StateID.Idle);

        FSMState playState = new PlayState(fsm);

        playState.AddTransition(Transition.Open, StateID.Idle);
        playState.AddTransition(Transition.Close, StateID.Sleep);
        playState.AddTransition(Transition.SeePlayer, StateID.Patrol);
        playState.AddTransition(Transition.Shopping, StateID.GoOut);

        fsm.AddState(sleepState);
        fsm.AddState(IdleState);
        fsm.AddState(patrolState);
        fsm.AddState(chaseState);
        fsm.AddState(barkState);
        fsm.AddState(comebackState);
        fsm.AddState(gooutState);
        fsm.AddState(playState);
    }