Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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"));
    }
Exemplo n.º 7
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);
    }
    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.º 9
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);
    }
Exemplo n.º 10
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();
    }
Exemplo n.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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.º 16
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.º 17
0
    void Start()
    {
        Fsm = new FSMSystem();
        ChaseState Chase = new ChaseState(Fsm);

        Chase.AddTransition(Transition.AttackPlayer, StateID.Attack);
        Fsm.AddStateID(Chase);
        AttackState Attack = new AttackState(Fsm);

        Attack.AddTransition(Transition.NoChasePlayer, StateID.Chase);
        Fsm.AddStateID(Attack);
    }
Exemplo n.º 18
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.º 19
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);
    }
        private void ConstructFSM()
        {
            pointList = waypointNetwork.Waypoints;

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

            // this is the same as AgentNavigation waypoint finder
            foreach (Transform obj in pointList)
            {
//                waypoints[i] = obj.transform;
                i++;
            }

            /*
             * Set all of the states and transitions.
             */
            ChaseState chase = new ChaseState(waypoints);

            chase.AddTransition(Transition.LostPlayer, FSMStateID.Patrolling);
            chase.AddTransition(Transition.ReachPlayer, FSMStateID.Attacking);
        }
Exemplo n.º 21
0
    //实例 FSMSystem
    void InitFSM()
    {
        fsm = new FSMSystem();

        //实例 FSMState
        FSMState patrolState = new PatrolState(fsm);
        FSMState chaseState  = new ChaseState(fsm);
        FSMState attackState = new AttackState(fsm);

        //添加状态
        fsm.AddState(patrolState);
        fsm.AddState(chaseState);
        fsm.AddState(attackState);

        //添加转换条件
        //Reason方法所在的状态添加转换条件
        //chaseState.AddTransition(Transition.ClosePalyer, StateID.Attack);  可以转换到攻击状态,因为转换的Reason方法在Chase状态中
        //attackState.AddTransition(Transition.ClosePalyer, StateID.Attack);  不可以转换攻击状态,因为转换的Reason方法在Chase状态中
        patrolState.AddTransition(Transition.SeePlayer, StateID.Chase);
        chaseState.AddTransition(Transition.LostPlayer, StateID.Patrol);
        chaseState.AddTransition(Transition.ClosePalyer, StateID.Attack);
        attackState.AddTransition(Transition.LostPlayer, StateID.Chase);
    }
Exemplo n.º 22
0
    private void Start()
    {
        fsmManager = new FSMManager <GameObject>();

        StateBase <GameObject> patrolState = new  PatrolState(fsmManager);

        patrolState.AddTransition(Transition.SeeEnemy, StateID.ChaseState);

        StateBase <GameObject> chaseState = new ChaseState(fsmManager);

        chaseState.AddTransition(Transition.LostEnemy, StateID.PatrolState);
        chaseState.AddTransition(Transition.ChaseUpEnemy, StateID.AttackState);

        StateBase <GameObject> attackState = new AttackState(fsmManager);

        attackState.AddTransition(Transition.SeeEnemy, StateID.ChaseState);

        fsmManager.AddState(patrolState);
        fsmManager.AddState(chaseState);
        fsmManager.AddState(attackState);

        fsmManager.InitState(patrolState);
    }
Exemplo n.º 23
0
    protected override void MakeFSM()
    {
        fsm = new FSMSystem();

        IdleState idle = new IdleState(gameObject);

        idle.AddTransition(Transition.PlayerVisible, StateID.Chase);
        fsm.AddState(idle);

        ChaseState chase = new ChaseState(gameObject);

        chase.AddTransition(Transition.PlayerNotVisible, StateID.Idle);
        fsm.AddState(chase);
    }
Exemplo n.º 24
0
    void Start()
    {
        animator = GetComponent <Animator>();

        var patrol      = new WonderState <Feed>(threshold, speed, this.transform, this.GetComponent <PatrolWonder>());
        var chase       = new ChaseState <Feed>(this.transform, target, speed);
        var alert       = new AlertState <Feed>(spotLight, this.GetComponent <Patrol>());
        var meleeattack = new PatrolAttackState <Feed>(this.transform);

        patrol.AddTransition(Feed.EnemigoEntraEnLOS, chase);

        chase.AddTransition(Feed.EnemigoSaleDeLOS, alert);
        chase.AddTransition(Feed.EntraEnRangoDeAtaque, meleeattack);

        alert.AddTransition(Feed.EnemigoEntraEnLOS, chase);
        alert.AddTransition(Feed.NoHayEnemigos, patrol);

        meleeattack.AddTransition(Feed.SaleDeRangoDeAtaque, chase);
        meleeattack.AddTransition(Feed.EnemigoSaleDeLOS, alert);

        stateMachine = new FSM <Feed>(patrol);

        los = GetComponent <LOS>();
    }
Exemplo n.º 25
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.º 26
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.º 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 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.º 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 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.º 31
0
    /// <summary>
    /// 初始化状态机
    /// </summary>
    public void InitFSM()
    {
        fsm = new FSMSystem();

        PatrolState patrolState = new PatrolState(this.gameObject.transform.position, this.gameObject);

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

        ChaseState chaseState = new ChaseState(this.gameObject);

        chaseState.AddTransition(Transition.LostPlayer, StateID.Patrol);
        chaseState.SetNavAgent(navAgent);
        this.transform.GetComponent <SphereCollider>().enabled = true;



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

        fsm.Start(StateID.Patrol);
    }
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();
    }