Exemplo n.º 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);
    }
Exemplo n.º 2
0
    private void ConstructFSM()
    {
        //Get the list of points
        pointList = GameObject.FindGameObjectsWithTag("WanderPoint");

        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }

        //Add Transition and State Pairs
        PatrolState patrol = new PatrolState(waypoints, this);

        //If the tank sees the player while patrolling, move to chasing state
        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        //If the tank loses health while patrolling, move to dead state
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        patrol.AddTransition(Transition.HalfHealth, FSMStateID.Rage);

        ChaseState chase = new ChaseState(waypoints, this);

        //If the tank loses the player while chasing, move to patrol state
        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        //If the tank reaches the player while attacking, move to attack state
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        //If the tank loses health while patrolling, move to dead state
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        chase.AddTransition(Transition.HalfHealth, FSMStateID.Rage);

        AttackState attack = new AttackState(waypoints, this);

        //If the tank loses the player while attacking, move to patrol state
        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        //If the player is within sight while attacking, move to chase state
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        //If the tank loses health while attacking, move to dead state
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        attack.AddTransition(Transition.HalfHealth, FSMStateID.Rage);

        DeadState dead = new DeadState(this);

        //When there is no health, go to dead state
        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        RageState rage = new RageState(this);

        rage.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        rage.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);

        //Add states to the state list
        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
        AddFSMState(rage);
    }
Exemplo n.º 3
0
    //Construct the Finite State Machine for the AI Car behavior
    private void ConstructFSM()
    {
        //Get the list of points
        pointList = GameObject.FindGameObjectsWithTag("WandarPoints");

        Transform[] waypoints = new Transform[pointList.Length];
        int i = 0;
        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }

        PatrolState patrol = new PatrolState(waypoints);
        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        ChaseState chase = new ChaseState(waypoints);
        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AttackState attack = new AttackState(waypoints);
        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        DeadState dead = new DeadState();
        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
    }
Exemplo n.º 4
0
    private void ConstructFSM()             //初始化拥有哪些状态,并为拥有的状态设置转化和状态ID
    {
        PatrolState tPatrolState = new PatrolState(wayPoints);

        tPatrolState.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        tPatrolState.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        ChaseState tChaseState = new ChaseState(wayPoints);

        tChaseState.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        tChaseState.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        tChaseState.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AttackState tAttackState = new AttackState(wayPoints);

        tAttackState.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        tAttackState.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        tAttackState.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        DeadState tDeadState = new DeadState();

        tDeadState.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AddFSMState(tPatrolState);
        AddFSMState(tPatrolState);
        AddFSMState(tPatrolState);
        AddFSMState(tPatrolState);


        Events.AddEvent(EventSign.GAME_START, DestroySelf, this);
        Events.Send(EventSign.GAME_START, new EventArg("123"));
    }
    private void ConstructFSM()
    {
        //Get the list of points
        //pointList = GameObject.FindGameObjectsWithTag("PatrolPoint");

        //Transform[] waypoints = new Transform[pointList.Length];
        //int i = 0;
        //foreach(GameObject obj in pointList)
        //{
        //    waypoints[i] = obj.transform;
        //    i++;
        //}

        int pointlength = Random.Range(3, 5);

        Debug.Log("pointlength = " + pointlength);
        Transform[] waypoints       = new Transform[pointlength];
        float       maxdistance     = 50;
        float       mindistance     = -30;
        GameObject  partpointparent = new GameObject();

        partpointparent.transform.position = role.transform.position;
        partpointparent.name = role.name + "[partolpoints]";

        for (int i = 0; i < pointlength; i++)
        {
            Vector3    pos = new Vector3(role.transform.position.x + CreatPatrolRange(maxdistance, mindistance), 0, role.transform.position.z + CreatPatrolRange(maxdistance, mindistance));
            GameObject go  = new GameObject();
            go.transform.position = pos;
            go.transform.parent   = partpointparent.transform;;
            waypoints[i]          = go.transform;
        }
        Debug.Log("waypoints length -> " + waypoints.Length);

        PatrolState patrol = new PatrolState(waypoints);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        ChaseState chase = new ChaseState(waypoints);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AttackState attack = new AttackState(waypoints);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
    }
Exemplo n.º 6
0
    void MakeFSM()
    {
        PatrolState patrol = new PatrolState();
        ChaseState  chase  = new ChaseState();
        AttackState attack = new AttackState();
        DeadState   dead   = new DeadState();
        IdleState   idle   = new IdleState();
        MoveState   move   = new MoveState();

        patrol.AddTransition(Transition.SawEnemy, chase);
        patrol.AddTransition(Transition.NoHP, dead);

        chase.AddTransition(Transition.LostEnemy, patrol);
        chase.AddTransition(Transition.ReachEnemy, attack);
        chase.AddTransition(Transition.NoHP, dead);

        attack.AddTransition(Transition.LostEnemy, patrol);
        attack.AddTransition(Transition.SawEnemy, chase);
        attack.AddTransition(Transition.NoHP, dead);

        AddState(StateID.Patrol, patrol);
        AddState(StateID.Chase, chase);
        AddState(StateID.Attack, attack);
        AddState(StateID.Dead, dead);



        m_stateMachine.Start(patrol);
    }
Exemplo n.º 7
0
    private void ConstructFSM()
    {
        FSMState patrol = new PatrolState(this);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.ReachedPlayer, FSMStateID.Attacking);
        AddFSMState(patrol);

        FSMState chase = new ChaseState();

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Searching);
        chase.AddTransition(Transition.ReachedPlayer, FSMStateID.Attacking);
        AddFSMState(chase);

        FSMState search = new SearchState(this);

        search.AddTransition(Transition.GiveUpSearching, FSMStateID.Patrolling);
        search.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        AddFSMState(search);

        FSMState attack = new AttackState(this);

        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.LostPlayer, FSMStateID.Searching);
        AddFSMState(attack);
    }
Exemplo n.º 8
0
    private void ConstructFSM()
    {
        //Get the list of points
        pointList = GameObject.FindGameObjectsWithTag("WandarPoint");

        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }

        PatrolState patrol = new PatrolState(waypoints, this);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.LowHealth, FSMStateID.Healing);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        patrol.AddTransition(Transition.HasBoredom, FSMStateID.Bored);

        ChaseState chase = new ChaseState(waypoints, this);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.LowHealth, FSMStateID.Healing);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AttackState attack = new AttackState(waypoints, this);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.LowHealth, FSMStateID.Healing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        HealState heal = new HealState(waypoints, this);

        heal.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        heal.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        heal.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        BoredState bored = new BoredState(waypoints, this);

        bored.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        bored.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        bored.AddTransition(Transition.LowHealth, FSMStateID.Healing);
        bored.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
        AddFSMState(heal);
        AddFSMState(bored);
    }
    private void ConstructFSM()
    {
        //Get the list of points
        //   pointList = GameObject.FindGameObjectsWithTag("WandarPoint");
        var pointList = gameObject.transform.Cast <Transform>().Where(c => c.gameObject.tag == "WandarPoint").Select(c => c.gameObject).ToArray();

        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;


        foreach (GameObject obj in pointList)
        {
            obj.GetComponent <Transform>().position = transform.position + new Vector3(Random.onUnitSphere.x * 5,
                                                                                       Random.onUnitSphere.y * 5, Random.onUnitSphere.z * 5);
            waypoints[i] = obj.transform;
            //	waypoints[i].position = new Vector3(Random.insideUnitSphere.x * 5,
            //	                                    Random.insideUnitSphere.z * 5, Random.insideUnitSphere.z * 5);

            i++;
        }

        PatrolState patrol = new PatrolState(waypoints);

        patrol.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing);
        patrol.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        patrol.SetStateDistances(chaseStartDist, attackStartDist);
        patrol.SetSpeed(speed / 2, rotationSpeed / 2);
        patrol.SetBounds(patrolBounds.x, patrolBounds.y, patrolBounds.z);

        ChaseState chase = new ChaseState(waypoints);

        chase.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling);
        chase.AddTransition(FSMTransition.PlayerReached, StateID.Attacking);
        chase.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        chase.SetStateDistances(chaseStartDist, attackStartDist);
        chase.SetSpeed(speed, rotationSpeed);

        AttackState attack = new AttackState(waypoints);

        attack.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling);
        attack.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing);
        attack.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        attack.SetStateDistances(chaseStartDist, attackStartDist);
        attack.SetSpeed(speed, rotationSpeed);
        attack.kamikaze = this.kamikaze;

        DeadState dead = new DeadState();

        dead.AddTransition(FSMTransition.NoHealth, StateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);

        //Start patrolling at given points
        patrol.FindNextPoint();
    }
Exemplo n.º 10
0
    private void ConstructFSM()
    {
        //Get the list of points
        pointList = GameObject.FindGameObjectsWithTag("WandarPoint");

        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }

        PatrolState patrol = new PatrolState(waypoints);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        patrol.AddTransition(Transition.Panic, FSMStateID.Fleeing);

        ChaseState chase = new ChaseState(waypoints);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        chase.AddTransition(Transition.Panic, FSMStateID.Fleeing);

        AttackState attack = new AttackState(waypoints);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        attack.AddTransition(Transition.Panic, FSMStateID.Fleeing);
        attack.AddTransition(Transition.TooCloseTooPlayer, FSMStateID.Evade);

        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        FleeState flee = new FleeState();

        flee.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        flee.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);

        EvadeState evade = new EvadeState();

        evade.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        evade.AddTransition(Transition.OutOfEvadingRange, FSMStateID.Patrolling);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
        AddFSMState(flee);
        AddFSMState(evade);
    }
Exemplo n.º 11
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);
    }
Exemplo n.º 12
0
    private void ConstructFSM()
    {
        pointList = GameObject.FindGameObjectsWithTag("DestinationPoint");

        Transform[] wayPoints = new Transform[pointList.Length];

        int i = 0;

        foreach (GameObject obj in pointList)
        {
            wayPoints[i] = obj.transform;
            i++;
        }

        PatrolState patrol = new PatrolState(wayPoints);

        patrol.AddTransition(Transition.FoundPlayer, FSMStateID.Chasing);

        ChaseState chase = new ChaseState(wayPoints);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachedPlayer, FSMStateID.Attacking);


        AddFSMState(patrol);
        AddFSMState(chase);
    }
Exemplo n.º 13
0
    protected void ConstructFSM()
    {
        // ________________
        // PatrolState
        PatrolState patrolState = new PatrolState(new EnemyStateData(GetComponent <EnemyBase>(), this), Points);

        patrolState.AddTransition(Transition.FoundTarget, FSMStateID.TrackTarget);
        AddFSMState(patrolState);

        // ________________
        // TrackPlayerState
        TrackPlayerState rushState = new TrackPlayerState(new EnemyStateData(GetComponent <EnemyBase>(), this));

        rushState.AddTransition(Transition.LostTarget, FSMStateID.Patrol);
        rushState.AddTransition(Transition.FoundTarget, FSMStateID.ShootPlayer);
        rushState.AddTransition(Transition.ApproachedPlayer, FSMStateID.Retreating);
        AddFSMState(rushState);


        // ________________
        // ShootPlayerState
        ShootPlayerState shootPlayerState = new ShootPlayerState(new EnemyStateData(GetComponent <EnemyBase>(), this));

        shootPlayerState.AddTransition(Transition.LostTarget, FSMStateID.Patrol);
        shootPlayerState.AddTransition(Transition.ApproachedPlayer, FSMStateID.Retreating);
        AddFSMState(shootPlayerState);


        // ________________
        // ShootPlayerState
        RetreatingState retreatingState = new RetreatingState(new EnemyStateData(GetComponent <EnemyBase>(), this));

        retreatingState.AddTransition(Transition.LostTarget, FSMStateID.Patrol);
        AddFSMState(retreatingState);
    }
Exemplo n.º 14
0
    // The NPC has two states: FollowPath and ChasePlayer
    // If it's on the first state and SawPlayer transition is fired, it changes to ChasePlayer
    // If it's on ChasePlayerState and LostPlayer transition is fired, it returns to FollowPath
    private void MakeFSM()
    {
        FollowPathState follow = new FollowPathState(/*path*/);

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

        ChasePlayerState chase = new ChasePlayerState();

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

        PatrolState patrolState = new PatrolState(PatrolWayPoints);

        patrolState.AddTransition(Transition.Alert, StateID.AlertNpc);

        AlertState alertState = new AlertState();

        alertState.AddTransition(Transition.Attack, StateID.AttackingPlayer);
        alertState.AddTransition(Transition.Patrol, StateID.Patroling);

        AttackState attackState = new AttackState();

        attackState.AddTransition(Transition.Alert, StateID.AlertNpc);


        fsm = new FSMSystem();
        fsm.AddState(patrolState);
        fsm.AddState(alertState);
        fsm.AddState(attackState);
        //fsm.AddState(chase);
        //fsm.AddState(follow);

        Debug.Log("First State: " + fsm.CurrentState.ToString());
    }
Exemplo n.º 15
0
    private void MakeFSM()
    {
        PatrolState patrol = new PatrolState(player, transform, path);

        patrol.AddTransition(Transition.GuardPlayer, StateID.GuardID);

        GuardState guard = new GuardState(player, transform);

        guard.AddTransition(Transition.AutoPatrol, StateID.PatrolID);
        guard.AddTransition(Transition.ChasingPlayer, StateID.ChasingID);

        ChaseState chase = new ChaseState(player, transform);

        chase.AddTransition(Transition.GuardPlayer, StateID.GuardID);
        chase.AddTransition(Transition.AttackPlayer, StateID.AttackID);

        AttackState attack = new AttackState(player, transform);

        attack.AddTransition(Transition.GuardPlayer, StateID.GuardID);
        attack.AddTransition(Transition.ChasingPlayer, StateID.ChasingID);

        fsm = new FSMSystem();

        fsm.AddState(patrol);
        fsm.AddState(guard);
        fsm.AddState(chase);
        fsm.AddState(attack);
    }
Exemplo n.º 16
0
    private void MakeFSM()
    {
        int i = Random.Range(0, 3);

        mFSM = new FSMSystem();
        if (i == 0)
        {
            PatrolState patrol = new PatrolState(gameObject, mFSM);
            patrol.AddTransition(Transition.CanAttack, StateID.Attack);
            patrol.AddTransition(Transition.SeeTarget, StateID.Chase);

            ChaseState chase = new ChaseState(gameObject, mFSM);
            chase.AddTransition(Transition.CanAttack, StateID.Attack);
            chase.AddTransition(Transition.LostTarget, StateID.Patrol);

            AttackState attack = new AttackState(gameObject, mFSM);
            attack.AddTransition(Transition.LostTarget, StateID.Patrol);
            attack.AddTransition(Transition.SeeTarget, StateID.Chase);

            mFSM.AddState(patrol, chase, attack);
        }
        if (i == 1)
        {
            ChaseState chase = new ChaseState(gameObject, mFSM);
            chase.AddTransition(Transition.CanAttack, StateID.Attack);
            chase.AddTransition(Transition.LostTarget, StateID.Patrol);

            AttackState attack = new AttackState(gameObject, mFSM);
            attack.AddTransition(Transition.LostTarget, StateID.Patrol);
            attack.AddTransition(Transition.SeeTarget, StateID.Chase);

            mFSM.AddState(chase, attack);
        }
        if (i == 2)
        {
            PatrolState patrol = new PatrolState(gameObject, mFSM);
            patrol.AddTransition(Transition.CanAttack, StateID.Attack);
            patrol.AddTransition(Transition.SeeTarget, StateID.Chase);
            AttackState attack = new AttackState(gameObject, mFSM);
            attack.AddTransition(Transition.LostTarget, StateID.Patrol);
            attack.AddTransition(Transition.SeeTarget, StateID.Chase);
            mFSM.AddState(patrol, attack);
        }
    }
Exemplo n.º 17
0
    protected override void MakeFSM()
    {
        PatrolState patrol = new PatrolState(globalWaypoints, gameObject);

        patrol.AddTransition(Transition.SawPlayer, StateID.Chasing);
        patrol.AddTransition(Transition.NoHealth, StateID.Dead);

        ChaseState chase = new ChaseState(chaseRange, gameObject);

        chase.AddTransition(Transition.LostPlayer, StateID.Patrolling);
        chase.AddTransition(Transition.NoHealth, StateID.Dead);

        DeadState dead = new DeadState();

        fsm = new FSMSystem();
        fsm.AddState(patrol);
        fsm.AddState(chase);
        fsm.AddState(dead);
    }
Exemplo n.º 18
0
    private void Start()
    {
        fsm = new FSMSystem();
        FSMState patrolState = new PatrolState(fsm);
        FSMState chaseState  = new ChaseState(fsm);

        fsm.AddState(patrolState);
        fsm.AddState(chaseState);
        patrolState.AddTransition(Transition.FindPlayer, StateID.ChaseState);
        chaseState.AddTransition(Transition.LosePlayer, StateID.PatrolState);
    }
Exemplo n.º 19
0
    private void ConstructFSM()
    {
        PatrolState patrol = new PatrolState(this);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        patrol.AddTransition(Transition.GotBored, FSMStateID.Bored);
        patrol.AddTransition(Transition.WantsTimeOff, FSMStateID.OffDuty);
        patrol.AddTransition(Transition.Hurt, FSMStateID.Repairing);
        patrol.AddTransition(Transition.WantsToHide, FSMStateID.Hiding);

        ChaseState chase = new ChaseState(this);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        chase.AddTransition(Transition.Hurt, FSMStateID.Repairing);

        AttackState attack = new AttackState(this);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        attack.AddTransition(Transition.Hurt, FSMStateID.Repairing);

        OffDutyState offduty = new OffDutyState(rigidbody.transform, this);

        offduty.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        offduty.AddTransition(Transition.RestedLongEnough, FSMStateID.Patrolling);
        offduty.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        offduty.AddTransition(Transition.WantsToHide, FSMStateID.Hiding);

        RepairState repair = new RepairState(this);

        repair.AddTransition(Transition.Healed, FSMStateID.Patrolling);
        repair.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        HideState hide = new HideState(this);

        hide.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        hide.AddTransition(Transition.RestedLongEnough, FSMStateID.Patrolling);

        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);


        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(offduty);
        AddFSMState(repair);
        AddFSMState(hide);
        AddFSMState(dead);
    }
Exemplo n.º 20
0
    void InitFsmSystem()
    {
        fSMSystem = new FSMSystem();
        FSMState patrolState = new PatrolState(fSMSystem);

        patrolState.AddTransition(Transition.SeePlayer, StateID.Chease);
        fSMSystem.AddState(patrolState);
        FSMState chaseState = new ChaseState(fSMSystem);

        chaseState.AddTransition(Transition.LosePlayer, StateID.Patrol);
        fSMSystem.AddState(chaseState);
    }
Exemplo n.º 21
0
    void Start()
    {
        rb = GetComponent <Rigidbody>();

        stateMachine = new StateMachine <StateAgent>();

        //patrol
        State <StateAgent>      state      = new PatrolState <StateAgent>(this);
        Transition <StateAgent> transition = new TransitionBool <StateAgent>(this, ref m_isDead, true);

        state.AddTransition(transition, "Death");
        transition = new TransitionFloat <StateAgent>(this, ref m_energy, 0.0f, TransitionFloat <StateAgent> .eCompare.LESS);
        state.AddTransition(transition, "Recharge");

        stateMachine.AddState("Patrol", state);
        stateMachine.AddState("Attack", new AttackState <StateAgent>(this));
        stateMachine.AddState("Death", new DeathState <StateAgent>(this));
        stateMachine.AddState("Recharge", new RechargeState <StateAgent>(this));

        stateMachine.SetState("Patrol");
    }
Exemplo n.º 22
0
    //FSM构建方法
    private void ConstructFSM()
    {
        //存放所有路点
        pointList = GameObject.FindGameObjectsWithTag("PatrolPoint");
        //所有路点的transform
        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }
        //描述AI的状态转换图
        PatrolState patrol = new PatrolState(waypoints);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        ChaseState chase = new ChaseState(waypoints);

        chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        chase.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AttackState attack = new AttackState(waypoints);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        attack.AddTransition(Transition.SawPlayer, FSMStateID.Chasing);
        attack.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);
    }
Exemplo n.º 23
0
    private void ConstructFSM()
    {
        PatrolState patrol = new PatrolState(this);

        patrol.AddTransition(Transition.SawPlayer, FSMStateID.Attacking);


        AttackState attack = new AttackState(this);

        attack.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);

        AddFSMState(patrol);
        AddFSMState(attack);
    }
Exemplo n.º 24
0
    private void ConstructFSM()
    {
        //Get the list of points


        Transform[] waypoints = new Transform[pointList.Length];
        int         i         = 0;

        foreach (GameObject obj in pointList)
        {
            waypoints[i] = obj.transform;
            i++;
        }
        //Add transitions
        PatrolState patrol = new PatrolState(waypoints);

        patrol.AddTransition(Transition.NoHealth, FSMStateID.Dead);
        patrol.AddTransition(Transition.SmelledSardine, FSMStateID.Investigating);


        InvestigateState investigate = new InvestigateState(waypoints);

        investigate.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
        investigate.AddTransition(Transition.NoHealth, FSMStateID.Dead);


        DeadState dead = new DeadState();

        dead.AddTransition(Transition.NoHealth, FSMStateID.Dead);



        //Add states to the fsmstates list
        AddFSMState(patrol);
        AddFSMState(dead);
        AddFSMState(investigate);
    }
Exemplo n.º 25
0
    /// <summary>
    /// 初始化状态机
    /// </summary>
    void InitFSM()
    {
        fsm = new FSMSystem();
        PatrolState patrolState = new PatrolState(waypoints, gameObject, player);

        // 巡逻状态添加事件,发现玩家则进行追逐
        patrolState.AddTransition(Transition.SawPlayer, StateId.Chase);
        ChaseState chaseState = new ChaseState(gameObject, player);

        // 追逐状态添加事件,丢失玩家则进行巡逻
        chaseState.AddTransition(Transition.LostPlayer, StateId.Patrol);
        fsm.AddState(patrolState);
        fsm.AddState(chaseState);
        // 初始状态是巡逻状态
        fsm.Start(StateId.Patrol);
    }
Exemplo n.º 26
0
    void InitFSM()
    {
        system = new FSMSystem();

        PatrolState patrolState = new PatrolState(wayPoints, gameObject, player);
        ChaseState  chaseState  = new ChaseState(gameObject, player);

        // 注册切换条件 对应的 状态
        patrolState.AddTransition(FSMTransition.SawPlayer, FSMStateId.Chase);
        chaseState.AddTransition(FSMTransition.LostPlayer, FSMStateId.Patrol);

        system.AddState(patrolState);
        system.AddState(chaseState);

        system.Start(FSMStateId.Patrol);
    }
Exemplo n.º 27
0
    /// <summary>
    /// 初始化状态机
    /// </summary>
    void InitFSM()
    {
        fsm = new FSMSystem();

        PatrolState partolState = new PatrolState(wayPoints, gameObject, player);

        partolState.AddTransition(Transition.SawPlayer, StateID.Chase);// 这里只有一个,如果还有其他转换条件,可以继续添加

        ChaseState chaseState = new ChaseState(gameObject, player);

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

        fsm.AddState(partolState);
        fsm.AddState(chaseState);

        fsm.Start(StateID.Patrol);
    }
Exemplo n.º 28
0
    void InitFSM()
    {
        fsm = new FSMSystem();

        PatrolState patrol = new PatrolState(wayPoint, npc, player);

        patrol.AddTransition(Transition.SawPlayer, StateId.Chase);

        ChaseState chase = new ChaseState(npc, player);

        chase.AddTransition(Transition.LostPlayer, StateId.Patrol);

        fsm.AddState(patrol);
        fsm.AddState(chase);

        fsm.Start(StateId.Patrol);
    }
Exemplo n.º 29
0
    void InitFSM()
    {
        fsm = new FSMSystem();

        PatrolState patrolState = new PatrolState(pathPoints, npc, player);

        patrolState.AddTransition(Transition.FindPlayer, StateId.Chase);

        ChaseState chaseState = new ChaseState(npc, player);

        chaseState.AddTransition(Transition.LosePlayer, StateId.Patrol);

        fsm.AddState(patrolState);
        fsm.AddState(chaseState);

        fsm.StartState(StateId.Patrol);
    }
Exemplo n.º 30
0
    void InitFSM()
    {
        fsm = new FSMSystem();

        PatrolState patrolState = new PatrolState(waypoints, this.gameObject, player);

        patrolState.AddTransition(Transition.SawPlayer, StateID.Chase);

        ChaseState chaseState = new ChaseState(this.gameObject, player);

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

        fsm.AddState(patrolState);
        fsm.AddState(chaseState);

        fsm.Start(StateID.Patrol);
    }
Exemplo n.º 31
0
    private void MakeFSM()
    {
        //TODO: Create two states (PatrolState and ChasePlayerState), using the constructors defined below.
        //   Add one transition to each state (so each state can transit to the other), using the function FSMState.AddTransition
        //   Add both states to the FSM at the end of this method

        PatrolState patrol = new PatrolState(gameObject, wp);

        patrol.AddTransition(Transition.SawPlayer, StateID.ChasingPlayerID);
        ChasePlayerState chase = new ChasePlayerState(gameObject, player);

        chase.AddTransition(Transition.LostPlayer, StateID.PatrollingID);
        chase.AddTransition(Transition.Dead, StateID.DeathID);
        DeathState death = new DeathState(gameObject);

        fsm = new FSMSystem();
        fsm.AddState(patrol);
        fsm.AddState(chase);
        fsm.AddState(death);
    }
Exemplo n.º 32
0
    private void ConstructFSM()
    {
        //Get the list of points
        //   pointList = GameObject.FindGameObjectsWithTag("WandarPoint");
        var pointList = gameObject.transform.Cast<Transform>().Where(c => c.gameObject.tag == "WandarPoint").Select(c => c.gameObject).ToArray();

        Transform[] waypoints = new Transform[pointList.Length];
        int i = 0;

        foreach (GameObject obj in pointList)
        {
            obj.GetComponent<Transform>().position = transform.position + new Vector3(Random.onUnitSphere.x * 5,
                                                                 Random.onUnitSphere.y * 5, Random.onUnitSphere.z * 5);
            waypoints[i] = obj.transform;
            //	waypoints[i].position = new Vector3(Random.insideUnitSphere.x * 5,
            //	                                    Random.insideUnitSphere.z * 5, Random.insideUnitSphere.z * 5);

            i++;
        }

        PatrolState patrol = new PatrolState(waypoints);
        patrol.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing);
        patrol.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        patrol.SetStateDistances(chaseStartDist, attackStartDist);
        patrol.SetSpeed(speed / 2, rotationSpeed / 2);
        patrol.SetBounds(patrolBounds.x, patrolBounds.y, patrolBounds.z);

        ChaseState chase = new ChaseState(waypoints);
        chase.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling);
        chase.AddTransition(FSMTransition.PlayerReached, StateID.Attacking);
        chase.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        chase.SetStateDistances(chaseStartDist, attackStartDist);
        chase.SetSpeed(speed, rotationSpeed);

        AttackState attack = new AttackState(waypoints);
        attack.AddTransition(FSMTransition.PlayerLost, StateID.Patrolling);
        attack.AddTransition(FSMTransition.PlayerSeen, StateID.Chasing);
        attack.AddTransition(FSMTransition.NoHealth, StateID.Dead);
        attack.SetStateDistances(chaseStartDist, attackStartDist);
        attack.SetSpeed(speed, rotationSpeed);
        attack.kamikaze = this.kamikaze;

        DeadState dead = new DeadState();
        dead.AddTransition(FSMTransition.NoHealth, StateID.Dead);

        AddFSMState(patrol);
        AddFSMState(chase);
        AddFSMState(attack);
        AddFSMState(dead);

        //Start patrolling at given points
        patrol.FindNextPoint();
    }