Exemple #1
0
    /// <summary>
    /// 初始化状态机时,构造一个状态机
    /// </summary>
    void ConstructFSM()
    {
        FSM = new FSMSystem();

        AttackState attackState = new AttackState(gameObject);

        attackState.AddTransition(Transition.LostEnemy, StateID.Wander);

        MoveToState moveToState = new MoveToState(gameObject, MoveTarget);

        moveToState.AddTransition(Transition.ReadyToAttack, StateID.Attack);
        moveToState.AddTransition(Transition.LostEnemy, StateID.Wander);

        WanderState wanderState = new WanderState(gameObject, wanderPoints);

        wanderState.AddTransition(Transition.SawEnemy, StateID.MoveTo);
        wanderState.AddTransition(Transition.SawItem, StateID.MoveTo);



        FSM.AddState(attackState);
        FSM.AddState(wanderState);
        FSM.AddState(moveToState);



        FSM.start(StateID.Wander);
    }