Example #1
0
    /// <summary>
    /// Start is called before the first frame update
    /// </summary>
    void Start()
    {
        // State concert
        States goToConcert = new States("Go to concert",
                                        () => Debug.Log("Enter concert state"),
                                        WatchConcert,
                                        () => Debug.Log("Leave concert state"));

        // State rest
        States goRest = new States("Go rest",
                                   () => Debug.Log("Enter rest state"),
                                   GoRest,
                                   () => Debug.Log("Leave rest state"));

        // State eat
        States goEat = new States("Go eat",
                                  () => Debug.Log("Enter eat state"),
                                  GoEat,
                                  () => Debug.Log("Leave eat state"));

        // Transition to go from concert to eat
        goToConcert.AddTransition(
            new Transition(
                () =>
                hunger < 30,
                () => Debug.Log("Agent is hungry"),
                goEat));

        // Transition to from concert to rest
        goToConcert.AddTransition(
            new Transition(
                () =>
                energy < 40,
                () => Debug.Log("Agent is tired"),
                goRest));

        // Transition to go from eat to concert
        goEat.AddTransition(
            new Transition(
                () =>
                hunger == 100,
                () => Debug.Log("Agent will return to concert"),
                goToConcert));

        // Transition to go from rest to concert
        goRest.AddTransition(
            new Transition(
                () =>
                energy == 100,
                () => Debug.Log("Agent will return to concert"),
                goToConcert));

        stateMachine = new StateMachine(goToConcert);
    }