Ejemplo n.º 1
0
 void DoActions(ref BrainAIComponent brain, ref EcsEntity entity)
 {
     for (int i = 0; i < actions.Length; i++)
     {
         actions[i].Act(ref brain, ref entity);
     }
 }
Ejemplo n.º 2
0
        void Scan(ref BrainAIComponent brain, ref EcsEntity entity)
        {
            if (brain.Agent.enabled)
            {
                brain.Agent.isStopped = true;
                brain.Agent.enabled   = false;
            }

            var turnSpeed = brain.EnemyStats.SearchingTurnSpeed * Time.deltaTime;

            var rb = entity.Get <MoveComponent>().RB;

            rb.transform.Rotate(new Vector3(0f, rb.transform.rotation.y + turnSpeed, 0f));
        }
Ejemplo n.º 3
0
        void CheckTransitions(ref BrainAIComponent brain)
        {
            for (int i = 0; i < transitions.Length; i++)
            {
                bool decisionSucceded = transitions[i].Decision.Decide(ref brain);

                if (decisionSucceded)
                {
                    brain.TransitionToState(transitions[i].TrueState);
                }
                else
                {
                    brain.TransitionToState(transitions[i].FalseState);
                }
            }
        }
Ejemplo n.º 4
0
        void Patrol(ref BrainAIComponent brain, ref EcsEntity entity)
        {
            var agent = brain.Agent;

            agent.enabled = true;

            agent.destination =
                brain
                .Waitpoints[brain.NextWayPoint]
                .position;

            var distToPoint = (agent.destination - agent.transform.position).magnitude;

            if (agent.remainingDistance <= agent.stoppingDistance && !agent.pathPending)
            {
                brain.NextWayPoint = (brain.NextWayPoint + 1) % brain.Waitpoints.Length;
            }
        }
Ejemplo n.º 5
0
        void Attack(ref BrainAIComponent brain, ref EcsEntity entity)
        {
            #if DEBUG
            Debug.DrawRay(brain.Eyes.position,
                          brain.Eyes.forward * brain.EnemyStats.AttackRange,
                          Color.red);
            #endif

            if (Physics.SphereCast(brain.Eyes.position,
                                   brain.EnemyStats.LookSphereCastRadius,
                                   brain.Eyes.forward,
                                   out RaycastHit hit,
                                   brain.EnemyStats.AttackRange,
                                   brain.PlayerLayer))
            {
                if (brain.IsCheckCountDownElapsed(brain.EnemyStats.AttackRate))
                {
                    Fire(ref entity);
                }
            }
        }
        bool Look(ref BrainAIComponent brain)
        {
            #if DEBUG
            Debug.DrawRay(brain.Eyes.position,
                          brain.Eyes.forward * brain.EnemyStats.LookRange,
                          Color.green);
            #endif

            if (Physics.SphereCast(brain.Eyes.position,
                                   brain.EnemyStats.LookSphereCastRadius,
                                   brain.Eyes.forward,
                                   out RaycastHit hit,
                                   brain.EnemyStats.LookRange,
                                   brain.PlayerLayer))
            {
                brain.ChaseTarget = hit.transform;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 7
0
 public abstract void Act(ref BrainAIComponent brain, ref EcsEntity entity);
Ejemplo n.º 8
0
 public override void Act(ref BrainAIComponent brain, ref EcsEntity entity)
 {
     Chase(ref brain, ref entity);
 }
Ejemplo n.º 9
0
 void Chase(ref BrainAIComponent brain, ref EcsEntity entity)
 {
     brain.Agent.enabled     = true;
     brain.Agent.destination = brain.ChaseTarget.position;
 }
 public override bool Decide(ref BrainAIComponent brain)
 {
     return(brain.ChaseTarget.gameObject.activeSelf);
 }
Ejemplo n.º 11
0
 public void UpdateState(ref BrainAIComponent brain, ref EcsEntity entity)
 {
     DoActions(ref brain, ref entity);
     CheckTransitions(ref brain);
 }
Ejemplo n.º 12
0
 public abstract bool Decide(ref BrainAIComponent brain);
Ejemplo n.º 13
0
 public override bool Decide(ref BrainAIComponent brain)
 {
     return(Scan(ref brain));
 }
Ejemplo n.º 14
0
 bool Scan(ref BrainAIComponent brain)
 {
     return(brain.IsCheckCountDownElapsed(brain.EnemyStats.SearchDuration));
 }