Exemplo n.º 1
0
    void InitStateMachine()
    {
        stateMachine = new fsm.FiniteStateMachine <Movement>();

        fsm.SteeringBehaviorState <Movement> idle = new fsm.SteeringBehaviorState <Movement>(this, stateMachine);
        idle.name = "idle";
        fsm.SteeringBehaviorState <Movement> walk = new fsm.SteeringBehaviorState <Movement>(this, stateMachine);
        walk.name = "walk";
        fsm.SteeringBehaviorState <Movement> attack = new fsm.SteeringBehaviorState <Movement>(this, stateMachine);
        attack.name = "attack";
        stateMachine.AddInitialState(idle);

        stateMachine.AddBool("attack");
        stateMachine.AddTrigger("haveTarget");
        stateMachine.AddFloat("velocity");

        foreach (steering.SteeringBehavior behavior in GetComponents <steering.SteeringBehavior>())
        {
            walk.AddBehavior(behavior);
        }

        idle.AddTransition(new fsm.Transition <Movement>("haveTarget", walk));
        walk.AddTransition(new fsm.Transition <Movement>("velocity", 0.1f, fsm.E_FloatOperator.LESSER, idle));
        walk.AddTransition(new fsm.Transition <Movement>("attack", true, attack));
        attack.AddTransition(new fsm.Transition <Movement>("attack", false, walk));
    }