Ejemplo n.º 1
0
    private void InitStateMachine()
    {
        blackboard = new StateBlackboard();
        blackboard.Add <bool>(BlackboardKey.DamageFlag, false);
        blackboard.Add <bool>(BlackboardKey.RepeatDamageFlag, false);
        blackboard.Add <Transform>(BlackboardKey.Transform, transform);
        blackboard.Add <float>(BlackboardKey.AttackRange, 0f);

        EnemyIdleState idleState = EnemyIdleState.Create(blackboard, animator, "Idle", 0);
        StateNode      idleNode  = new StateNode(idleState, new Condition(() => { return(true); }));

        SetAnimTriggerAction walkAction       = new SetAnimTriggerAction(blackboard, animator, "Run");
        MeleeAttackState     meleeAttackState = MeleeAttackState.Create(blackboard, animator, navAgent, attackValidator.MeleeAttacks, transform, BlackboardKey.AttackRange, BlackboardKey.AnimTrigger, walkAction, 300);
        StateNode            attackNode       = new StateNode(meleeAttackState, new Condition(() => { return(target != null); }));

        DamageState damageState = DamageState.Create(blackboard, animator, "Damage", 500);
        StateNode   damageNode  = new StateNode(damageState, new Condition(() => { return(blackboard.Get <bool>(BlackboardKey.DamageFlag)); }));

        DeathState deathState = DeathState.Create(blackboard, animator, "Death", int.MaxValue);
        StateNode  deathNode  = new StateNode(deathState, new Condition(() => { return(!self.IsAlive); }));

        List <StateNode> nodes = new List <StateNode>();

        nodes.Add(idleNode);
        nodes.Add(attackNode);
        nodes.Add(damageNode);
        nodes.Add(deathNode);

        stateMachine = new StateMachine(blackboard, nodes, idleState);
    }
Ejemplo n.º 2
0
    protected override void InitStateMachine()
    {
        m_FSM      = new FSMSystem();
        m_FSM.attr = attr;

        idleState  = new EnemyIdleState();
        moveState  = new EnemyMoveState();
        fightState = new EnemyFightState();
        deathState = new EnemyDeathState();



        m_FSM.AddState(idleState, this);
        idleState.AddTransition(Transition.IsMove, StateID.Move);
        idleState.AddTransition(Transition.IsFight, StateID.Fight);


        m_FSM.AddState(moveState, this);
        moveState.AddTransition(Transition.IsIdle, StateID.Idle);
        moveState.AddTransition(Transition.IsFight, StateID.Fight);


        m_FSM.AddState(fightState, this);
        fightState.AddTransition(Transition.IsIdle, StateID.Idle);

        m_FSM.AddState(deathState, this);

        //初始状态为Idle
        m_FSM.SetCurrentState(idleState);
    }
Ejemplo n.º 3
0
    private void Awake()
    {
        chasingState   = new ChasingState(this);
        idleState      = new EnemyIdleState(this);
        returningState = new ReturningState(this);
        attackingState = new AttackingState(this);
        visiblePlayers = new List <GameObject>();

        returnPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z);

        eyes         = transform.FindChild("Eyes");
        health       = GetComponent <EnemyHealth>();
        attack       = GetComponent <EnemyAttack>();
        sounds       = GetComponent <EnemySoundController>();
        animator     = GetComponent <EnemyAnimationController>();
        navMeshAgent = GetComponent <NavMeshAgent>();

        isTargetting = false;

        if (transform.parent.CompareTag("EnemyMob"))
        {
            mobKnowledge = GetComponentInParent <EnemyMobKnowledge>();
        }

        tm = GameObject.FindWithTag("TeamManager").GetComponent <TeamManager>();
    }
Ejemplo n.º 4
0
 private void Awake()
 {
     //Initialise
     StateMachine = new EnemyStateMachine();
     IdleState    = new EnemyIdleState(this, StateMachine, enemyData, "idle");
     MoveState    = new EnemyMoveState(this, StateMachine, enemyData, "move");
     AttackState  = new EnemyAttackState(this, StateMachine, enemyData, "inAttack");
     DeathState   = new EnemyDeathState(this, StateMachine, enemyData, "isDead");
 }
Ejemplo n.º 5
0
 private void InitStates()
 {
     State       = new FSM <EnemyState, BaseEnemyAIState>();
     _idleState  = new EnemyIdleState(this);
     _chaseState = new EnemyChaseState(this);
     State.Add(EnemyState.IDLE, _idleState);
     State.Add(EnemyState.CHASE, _chaseState);
     State.SetState(EnemyState.IDLE);
 }
Ejemplo n.º 6
0
    private void Start()
    {
        Gun.Enabled      = false;
        IdleState        = new EnemyIdleState(this);
        FocusTargetState = new EnemyFocusTargetState(this);
        DeadState        = new EnemyDeadState(this);

        StateMachine = new StateMachine();
        StateMachine.ChangeState(IdleState);
    }
Ejemplo n.º 7
0
    protected override void InitState()
    {
        base.InitState();

        State idleState   = new EnemyIdleState();
        State attackState = new AttackState();


        idleState.Init(this);
        attackState.Init(this);

        _stateDic[eState.IDLE]   = idleState;
        _stateDic[eState.ATTACK] = attackState;
    }
Ejemplo n.º 8
0
    private void Awake()
    {
        enemy = GetComponent <Enemy>();
        anim  = GetComponent <Animator>();

        enemyIdleState        = new EnemyIdleState(this);
        enemyWalkState        = new EnemyWalkState(this);
        enemyRangeAttackState = new EnemyRangeAttackState(this);
        enemyMeleeAttackState = new EnemyMeleeAttackState(this);
        enemyMagicAttackState = new EnemyMagicAttackState(this);
        enemyBombAttackState  = new EnemyBombAttackState(this);
        enemyFreezeState      = new EnemyFreezeState(this);
        enemyDieState         = new EnemyDieState(this);
        isWaiting             = false;
    }
Ejemplo n.º 9
0
    void Start()
    {
        base.onStart();
        moveSpeed   = DefaultSpeed;
        sceneLoader = GameObject.FindGameObjectWithTag("MenuCanvas").GetComponent <SceneLoader>();

        if (tag == "Capataz")
        {
            maxHealth = 30;
        }
        else
        {
            maxHealth = Random.Range(3, 6);
            spawner   = GameObject.FindGameObjectWithTag("EnemySpawner").GetComponent <EnemySpawner>();
        }

        health       = maxHealth;
        currentState = new EnemyIdleState(this);
    }
Ejemplo n.º 10
0
    private void InitStateMachine()
    {
        blackboard = new StateBlackboard();
        blackboard.Add <bool>(BlackboardKey.DamageFlag, false);
        blackboard.Add <bool>(BlackboardKey.RepeatDamageFlag, false);
        blackboard.Add <Transform>(BlackboardKey.Transform, transform);
        blackboard.Add <float>(BlackboardKey.RunRange, 3f);

        EnemyIdleState idleState = EnemyIdleState.Create(blackboard, animator, "Idle", 0);
        StateNode      idleNode  = new StateNode(idleState, new Condition(() => { return(true); }));

        SetAnimTriggerAction       idleAction        = new SetAnimTriggerAction(blackboard, animator, "Idle");
        SetAnimTriggerAction       runAction         = new SetAnimTriggerAction(blackboard, animator, "Run");
        TimerAction                timerAction       = new TimerAction(blackboard, 0.5f, 1.5f);
        SetRandomDestinationAction destinationAction = new SetRandomDestinationAction(blackboard, transform.position, 6f);
        MoveToDestinationAction    moveToAction      = new MoveToDestinationAction(blackboard, navAgent);
        SetSkillAction             setSkillAction    = new SetSkillAction(blackboard, skillController);
        LookAtTargetAction         lookAtAction      = new LookAtTargetAction(blackboard, transform);
        SetAnimTriggerAction       attackAction      = new SetAnimTriggerAction(blackboard, animator, BlackboardKey.AnimTrigger, true);
        RangedAttackState          attackState       = new RangedAttackState(blackboard, idleAction, timerAction, destinationAction, runAction, moveToAction, setSkillAction, lookAtAction, attackAction, 300);
        StateNode attackNode = new StateNode(attackState, new Condition(() => target != null));

        DamageState damageState = DamageState.Create(blackboard, animator, "Damage", 500);
        StateNode   damageNode  = new StateNode(damageState, new Condition(() => { return(blackboard.Get <bool>(BlackboardKey.DamageFlag)); }));

        DeathState deathState = DeathState.Create(blackboard, animator, "Death", int.MaxValue);
        StateNode  deathNode  = new StateNode(deathState, new Condition(() => { return(!self.IsAlive); }));

        List <StateNode> nodes = new List <StateNode>();

        nodes.Add(idleNode);
        nodes.Add(attackNode);
        nodes.Add(damageNode);
        nodes.Add(deathNode);

        stateMachine = new StateMachine(blackboard, nodes, idleState);
    }
Ejemplo n.º 11
0
 protected virtual void Awake()
 {
     IdleState      = new EnemyIdleState(this, _enemy);
     KnockbackState = new EnemyKnockbackState(this, _enemy);
     DeathState     = new EnemyDeathState(this, _enemy);
 }
Ejemplo n.º 12
0
 //Called once
 public override void Idle()
 {
     currentState = new EnemyIdleState(this);
 }