AddState() public méthode

This method places new states inside the FSM, or prints an ERROR message if the state was already inside the List. First state added is also the initial state.
public AddState ( FsmState, s ) : void
s FsmState,
Résultat void
Exemple #1
0
    //建造状态机
    private void MakeFSM()
    {
        InspectionState inspection = new InspectionState();

        inspection.AddTransition(Transition.SawPlayer, StateID.ChasingPlayer);
        inspection.AddTransition(Transition.LostPlayer, StateID.FollowingPath);

        PatrolState follow = new PatrolState(transform.position, scope);

        follow.AddTransition(Transition.SawPlayer, StateID.ChasingPlayer);
        follow.AddTransition(Transition.ArrivePath, StateID.Inspection);

        ChasePlayerState chase = new ChasePlayerState();

        chase.AddTransition(Transition.LostPlayer, StateID.FollowingPath);
        chase.AddTransition(Transition.NearPlayer, StateID.AttackPlayer);

        AttackPlayerState attack = new AttackPlayerState();

        attack.AddTransition(Transition.LostPlayer, StateID.FollowingPath);

        fsm = new FsmSystem();
        fsm.AddState(inspection);//添加状态到状态机,第一个添加的状态将作为初始状态
        fsm.AddState(follow);
        fsm.AddState(chase);
        fsm.AddState(attack);
    }
Exemple #2
0
    // Use this for initialization
    void Start()
    {
        hearts        = new GameObject[3];
        bulletDisplay = new GameObject[3];

        fsm = new FsmSystem();
        fsm.AddState(new FsmState(FsmStateId.Player)
                     .WithUpdateAction(PlayerUpdate)
                     .WithTransition(FsmTransitionId.Complete, FsmStateId.Bullets)
                     );
        fsm.AddState(new FsmState(FsmStateId.Bullets)
                     .WithBeforeEnteringAction(BulletProcess)
                     .WithTransition(FsmTransitionId.Complete, FsmStateId.Monster)
                     );
        fsm.AddState(new FsmState(FsmStateId.Monster)
                     .WithBeforeEnteringAction(MonsterProcess)
                     .WithTransition(FsmTransitionId.Complete, FsmStateId.Player)
                     );

        GenLevel();

        // add the health display
        for (int i = 0; i < 3; i++)
        {
            bulletDisplay [i] = (GameObject)Instantiate(spriteHolder, new Vector3(i + 3, map.sy, 0), Quaternion.identity);
            bulletDisplay [i].GetComponent <SpriteRenderer> ().sprite = bulletV;
            bulletDisplay [i].GetComponent <SpriteRenderer> ().color  = Color.grey;
            hearts [i] = (GameObject)Instantiate(spriteHolder, new Vector3(i, map.sy, 0), Quaternion.identity);
            hearts [i].GetComponent <SpriteRenderer> ().sprite = heart;
            hearts [i].GetComponent <SpriteRenderer> ().color  = Color.red;
        }

        // center the camera on the game
        Camera.main.transform.position = new Vector3(map.sx / 2, map.sy / 2, -10);
    }
Exemple #3
0
    // Use this for initialization
    void Start()
    {
        enemyFsm = new FsmSystem();
        FsmStateBase patrol = new PatrolState(player, transform, enemyFsm);
        FsmStateBase trace  = new TraceState(player, transform, enemyFsm);
        FsmStateBase attack = new AttackState(player, transform, enemyFsm);

        enemyFsm.AddState(patrol);
        enemyFsm.AddState(trace);
        enemyFsm.AddState(attack);
    }
Exemple #4
0
    private void Start()
    {
        EnemyFollowState followState = new EnemyFollowState();

        followState.onFixedUpdateMethod += onUpdateFollowState;
        EnemyPatrolState patrolState = new EnemyPatrolState();

        patrolState.onFixedUpdateMethod += onUpdatePatrolState;

        fsmSystem = new FsmSystem();
        fsmSystem.AddState(followState);
        fsmSystem.AddState(patrolState);
        fsmSystem.ChangeState(StateType.EnemyPatrol);

        enemy  = this.gameObject.GetComponent <EnemyCharacter>();
        player = GameObject.FindGameObjectWithTag("Player");
    }
Exemple #5
0
        public static void AddState <T>(BaseEntity entity, FsmSystem system, E_StateId stateId)
            where T : FsmState, new()
        {
            T t = new T();

            t.entity = entity;
            system.AddState(t);
        }
Exemple #6
0
    void Start()
    {
        _fsm = FsmSystem <MenuStates> .Initialize(this);

        foreach (var obj in _menus)
        {
            _fsm.AddState(obj, obj.State);
        }
        _fsm.Push(MenuStates.Main);

        PlayerSettings.Instance.OnNameChange = UpdateName;
        UpdateName();
    }
Exemple #7
0
        private void InitFSMSystem()
        {
            fsm = new FsmSystem();

            SeekTarget seekTarget = new SeekTarget(this, fsm, anim);

            seekTarget.AddTransition(Transition.MoveToTarget, StateID.MoveToTarget);
            seekTarget.AddTransition(Transition.Attack, StateID.Attack);

            MoveToTarget moveToTarget = new MoveToTarget(this, fsm, anim);

            moveToTarget.AddTransition(Transition.SeekTarget, StateID.SeekTarget);
            moveToTarget.AddTransition(Transition.Attack, StateID.Attack);

            AttackTarget attackTarget = new AttackTarget(this, fsm, anim);

            attackTarget.AddTransition(Transition.SeekTarget, StateID.SeekTarget);
            attackTarget.AddTransition(Transition.MoveToTarget, StateID.MoveToTarget);

            fsm.AddState(seekTarget);
            fsm.AddState(moveToTarget);
            fsm.AddState(attackTarget);
        }
Exemple #8
0
    // Use this for initialization
    void Start()
    {
        player = FindObjectOfType <Player>();

        IdleState idleState = new IdleState();

        idleState.onEnterMethod       += OnEnterIdleState;
        idleState.onUpdateMethod      += OnUpDateIdleState;
        idleState.onFixedUpdateMethod += OnFixedUpDateIdleState;
        RunState runState = new RunState();

        runState.onFixedUpdateMethod += OnFixedUpDateRunState;
        runState.onUpdateMethod      += OnUpDateRunState;
        runState.onEnterMethod       += OnEnterRunState;
        JumpState jumpState = new JumpState();

        jumpState.onEnterMethod += OnEnterJumpState;
        AttackIdleState AttackIdleState = new AttackIdleState();

        AttackIdleState.onEnterMethod  += OnEnterAttackIdleState;
        AttackIdleState.onUpdateMethod += OnUpdateAttackIdleState;

        AttackWalkState attackWalkState = new AttackWalkState();

        attackWalkState.onFixedUpdateMethod += OnFixedUpDateAttackWalkState;
        attackWalkState.onUpdateMethod      += OnUpDateAttackWalkState;
        attackWalkState.onEnterMethod       += OnEnterAttackWalkState;

        AttackDoState attackDoState = new AttackDoState();

        //attackDoState.onFixedUpdateMethod += OnFixedUpDateAttackWalkState;
        attackDoState.onUpdateMethod += OnUpDateAttackDoState;
        attackDoState.onEnterMethod  += OnEnterAttackDoState;

        fsmSystem = new FsmSystem();
        fsmSystem.AddState(idleState);
        fsmSystem.AddState(runState);
        fsmSystem.AddState(jumpState);
        fsmSystem.AddState(AttackIdleState);
        fsmSystem.AddState(attackWalkState);
        fsmSystem.AddState(attackDoState);
        fsmSystem.ChangeState(StateType.FSM_IDLE);
    }
 /// <summary>
 /// 添加一个状态节点
 /// </summary>
 public void AddState(FsmState state)
 {
     InternalSystem.AddState(state);
 }
    // Use this for initialization
    void Start()
    {
        hearts = new GameObject[3];
        bulletDisplay = new GameObject[3];

        fsm = new FsmSystem ();
        fsm.AddState (new FsmState (FsmStateId.Player)
            .WithUpdateAction (PlayerUpdate)
            .WithTransition (FsmTransitionId.Complete, FsmStateId.Bullets)
        );
        fsm.AddState (new FsmState (FsmStateId.Bullets)
            .WithBeforeEnteringAction (BulletProcess)
            .WithTransition (FsmTransitionId.Complete, FsmStateId.Monster)
        );
        fsm.AddState (new FsmState (FsmStateId.Monster)
            .WithBeforeEnteringAction (MonsterProcess)
            .WithTransition (FsmTransitionId.Complete, FsmStateId.Player)
        );

        GenLevel ();

        // add the health display
        for (int i = 0; i < 3; i++) {
            bulletDisplay [i] = (GameObject)Instantiate (spriteHolder, new Vector3 (i+3, map.sy, 0), Quaternion.identity);
            bulletDisplay [i].GetComponent<SpriteRenderer> ().sprite = bulletV;
            bulletDisplay [i].GetComponent<SpriteRenderer> ().color = Color.grey;
            hearts [i] = (GameObject)Instantiate (spriteHolder, new Vector3 (i, map.sy, 0), Quaternion.identity);
            hearts [i].GetComponent<SpriteRenderer> ().sprite = heart;
            hearts [i].GetComponent<SpriteRenderer> ().color = Color.red;
        }

        // center the camera on the game
        Camera.main.transform.position = new Vector3 (map.sx / 2, map.sy / 2, -10);
    }