Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        fsm                 = new FSM("AITest FSM Two");
        MoveLeftState       = fsm.AddState("MoveLeftState");
        MoveRightState      = fsm.AddState("MoveRightState");
        MoveLeftAction      = new MoveAction(MoveLeftState);
        MoveRightAction     = new MoveAction(MoveRightState);
        MoveLeftTextAction  = new TextAction(MoveLeftState);
        MoveRightTextAction = new TextAction(MoveRightState);

        //This adds the actions to the state and add state to it's transition map
        MoveLeftState.AddAction(MoveLeftTextAction);
        MoveLeftState.AddAction(MoveLeftAction);
        MoveRightState.AddAction(MoveRightTextAction);
        MoveRightState.AddAction(MoveRightAction);

        MoveLeftState.AddTransition("ToRight", MoveRightState);
        MoveRightState.AddTransition("ToLeft", MoveLeftState);

        //this initializes the actions
        MoveLeftTextAction.Init("AI Moving Left", 1f, "");
        MoveRightTextAction.Init("AI Moving Right", 1f, "");
        MoveLeftAction.Init(this.transform, new Vector3(1, 0, 0), new Vector3(-1, 0, 0), 1.0f, "ToRight");
        MoveRightAction.Init(this.transform, new Vector3(-1, 0, 0), new Vector3(1, 0, 0), 1.0f, "ToLeft");

        //Starts the FSM
        fsm.Start("MoveLeftState");
    }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Awake()
    {
        damage       = enemyPreset.damage;
        moveTime     = enemyPreset.moveTime;
        idleTimeMin  = enemyPreset.idleTimeMin;
        idleTimeMax  = enemyPreset.idleTimeMax;
        wanderRadius = enemyPreset.wanderRadius;

        home = transform.position;

        trigger = GetComponentInChildren <DetectPlayer>();

        trigger.GetComponent <SphereCollider>().radius = enemyPreset.detectionRadius;

        navMeshAgent = GetComponent <NavMeshAgent>();

        navMeshAgent.speed = enemyPreset.speed;

        fsm = new FSM("MeleeAI FSM");

        WanderState = fsm.AddState("WanderState");
        IdleState   = fsm.AddState("IdleState");
        AlertState  = fsm.AddState("AlertState");
        MeleeState  = fsm.AddState("MeleeState");

        WanderAction = new WanderAction(WanderState);
        IdleAction   = new TextAction(IdleState);
        alertAction  = new AlertAction(AlertState);
        meleeAction  = new MeleeAction(MeleeState);

        WanderState.AddAction(WanderAction);
        IdleState.AddAction(IdleAction);
        AlertState.AddAction(alertAction);
        MeleeState.AddAction(meleeAction);

        WanderState.AddTransition("ToIdle", IdleState);
        WanderState.AddTransition("PlayerDetect", AlertState);
        IdleState.AddTransition("ToWander", WanderState);
        IdleState.AddTransition("PlayerDetect", AlertState);

        AlertState.AddTransition("ToIdle", IdleState);
        AlertState.AddTransition("ToMelee", MeleeState);
        MeleeState.AddTransition("ToAlert", AlertState);

        WanderAction.Init(this.transform, home, navMeshAgent, wanderRadius, moveTime, "ToIdle");
        IdleAction.Init("Idling", Random.Range(idleTimeMin, idleTimeMax), "ToWander");

        alertAction.Init(trigger, navMeshAgent, "ToIdle");
        meleeAction.Init(this.transform, damage, trigger, FindObjectOfType <PlayerManager>(), "ToAlert");

        fsm.Start("IdleState");
    }
Ejemplo n.º 3
0
    private void Start()
    {
        fsm          = new FSM("AITest FSM");
        IdleState    = fsm.AddState("IdleState");
        PatrolState  = fsm.AddState("PatrolState");
        PatrolAction = new TextAction(PatrolState);
        IdleAction   = new TextAction(IdleState);

        PatrolState.AddAction(PatrolAction);
        IdleState.AddAction(IdleAction);

        PatrolState.AddTransition("ToIdle", IdleState);
        IdleState.AddTransition("ToPatrol", PatrolState);

        PatrolAction.Init("AI on patrol", 3f, "ToIdle");
        IdleAction.Init("AI on idle", 2f, "ToPatrol");

        fsm.Start("IdleState");
    }
Ejemplo n.º 4
0
    private void Start()
    {
        fsm          = new FSM("AITest FSM");
        idleState    = fsm.AddState("IdleState");
        patrolState  = fsm.AddState("PatrolState");
        idleAction   = new TextAction(idleState);
        patrolAction = new TextAction(patrolState);

        //This adds the actions to the state and add state to it's transition map
        patrolState.AddAction(patrolAction);
        idleState.AddAction(idleAction);

        patrolState.AddTransition("ToIdle", idleState);
        idleState.AddTransition("ToPatrol", patrolState);

        patrolAction.Init("AI on Patrol", 3.0f, "ToIdle");
        idleAction.Init("AI on Idle", 2.0f, "ToPatrol");

        fsm.Start("IdleState");
    }