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); }
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); }
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>(); }
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"); }
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); }
private void Start() { Gun.Enabled = false; IdleState = new EnemyIdleState(this); FocusTargetState = new EnemyFocusTargetState(this); DeadState = new EnemyDeadState(this); StateMachine = new StateMachine(); StateMachine.ChangeState(IdleState); }
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; }
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; }
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); }
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); }
protected virtual void Awake() { IdleState = new EnemyIdleState(this, _enemy); KnockbackState = new EnemyKnockbackState(this, _enemy); DeathState = new EnemyDeathState(this, _enemy); }
//Called once public override void Idle() { currentState = new EnemyIdleState(this); }