예제 #1
0
 private void EnterState(AiStateController controller)
 {
     if (hasEnterStateAction)
     {
         enterStateAction.Act(controller);
     }
 }
예제 #2
0
#pragma warning restore CS0649

        /*****************************
        *           Init            *
        *****************************/

        /*****************************
        *          Update           *
        *****************************/

        /*****************************
        *          Methods          *
        *****************************/

        public override void Act(AiStateController controller)
        {
            _objectPosition = controller.transform.position;
            _targetPosition = controller.Target.transform.position;
            _distance       = Vector3.Distance(_objectPosition, _targetPosition);

            if (_distance < minDistance)
            {
                _direction                  = ((_objectPosition.x - _targetPosition.x) < 0) ? Vector3.left : Vector3.right;
                controller.TargetSpeed      = _direction * controller.Speed;
                controller.SetGfxDirectionX = _direction.x;
            }
            else if (_distance > maxDistance)
            {
                _direction                  = ((_objectPosition.x - _targetPosition.x) < 0) ? Vector3.right : Vector3.left;
                controller.TargetSpeed      = _direction * controller.Speed;
                controller.SetGfxDirectionX = _direction.x;
            }
            else
            {
                _direction                  = ((_objectPosition.x - _targetPosition.x) < 0) ? Vector3.right : Vector3.left;
                controller.TargetSpeed      = Vector2.zero;
                controller.SetGfxDirectionX = _direction.x;
            }
        }
예제 #3
0
 private void ExitState(AiStateController controller)
 {
     if (hasExitStateAction)
     {
         exitStateAction.Act(controller);
     }
 }
예제 #4
0
 private void ExecuteActions(AiStateController controller)
 {
     foreach (var action in actions)
     {
         action.Act(controller);
     }
 }
예제 #5
0
#pragma warning restore CS0649

        /*****************************
        *          Methods          *
        *****************************/
        public void UpdateState(AiStateController controller)
        {
            if (CheckForTransitions(controller))
            {
                ExecuteActions(controller);
            }
        }
예제 #6
0
#pragma warning restore CS0649

        /*****************************
        *           Init            *
        *****************************/

        /*****************************
        *          Update           *
        *****************************/

        /*****************************
        *          Methods          *
        *****************************/

        public override bool Evaluate(AiStateController controller)
        {
            _objectPosition = controller.transform.position;
            _targetPosition = controller.Target.transform.position;
            _distance       = Vector3.Distance(_objectPosition, _targetPosition);

            if (!(_distance > looseAggroDistance))
            {
                return(false);
            }

            controller.Target = null;
            return(true);
        }
예제 #7
0
#pragma warning restore CS0649

        /*****************************
        *           Init            *
        *****************************/

        /*****************************
        *          Update           *
        *****************************/

        /*****************************
        *          Methods          *
        *****************************/

        public override void Act(AiStateController controller)
        {
            _objectPosition = controller.gameObject.transform.position;
            _targetPosition = controller.TargetPosition;
            _distance       = Vector3.Distance(_objectPosition, _targetPosition);

            _direction = ((_objectPosition.x - _targetPosition.x) < 0) ? Vector3.right : Vector3.left;

            if (controller.HasCollidedWithOtherEnemy || _distance < 1)
            {
                controller.TargetPosition = controller.GetNextPatrolPoint;
            }

            controller.TargetSpeed      = _direction * controller.Speed;
            controller.SetGfxDirectionX = _direction.x;
        }
예제 #8
0
#pragma warning disable CS0649

        /*****************************
        *         Variables         *
        *****************************/

#pragma warning restore CS0649

        /*****************************
        *           Init            *
        *****************************/

        /*****************************
        *          Update           *
        *****************************/

        /*****************************
        *          Methods          *
        *****************************/

        public override void Act(AiStateController controller)
        {
            switch (controller.CastSpellState)
            {
            case SpellCastingState.Waiting:

                if (controller.EnemyIsReadyToCastSpell())
                {
                    controller.CastSpellState = SpellCastingState.Casting;
                    controller.SpellLength    = Random.Range(0, controller.MaxSpellLength) + 1;
                }

                break;

            case SpellCastingState.Casting:

                if (controller.SpellLength > 0 && controller.EnemyIsReadyToAddSpell())
                {
                    controller.AddRandomSpell();
                    controller.SpellLength--;
                }

                if (controller.SpellLength == 0)
                {
                    controller.CastSpellState = SpellCastingState.Firing;
                }

                break;

            case SpellCastingState.Firing:

                if (controller.EnemyIsReadyToFire())
                {
                    controller.FireSpell();
                    controller.CastSpellState = SpellCastingState.Waiting;
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #9
0
        private bool CheckForTransitions(AiStateController controller)
        {
            foreach (var transition in transitions)
            {
                if (!transition.decision.Evaluate(controller))
                {
                    continue;
                }

                controller.currentState.ExitState(controller);
                transition.nextState.EnterState(controller);

                controller.currentState = transition.nextState;
                controller.OnStateChanged();
                return(false);
            }

            return(true);
        }
예제 #10
0
#pragma warning restore CS0649

        /*****************************
        *           Init            *
        *****************************/

        /*****************************
        *          Update           *
        *****************************/

        /*****************************
        *          Methods          *
        *****************************/

        public override bool Evaluate(AiStateController controller)
        {
            var numColliders = Physics2D.OverlapCircleNonAlloc(controller.Position, searchRadius,
                                                               _hitColliders, searchLayerMask);
            var minDist = 100000f;

            if (numColliders <= 0)
            {
                return(false);
            }

            for (var index = 0; index < _hitColliders.Length; index++)
            {
                var hitCollider = _hitColliders[index];
                _hitColliders[index] = null;

                if (hitCollider == null ||
                    controller.gameObject.transform.GetInstanceID() == hitCollider.transform.GetInstanceID())
                {
                    continue;
                }

                if (hitCollider.gameObject.CompareTag("Enemy"))
                {
                    //controller.targetPosition = controller.GetNextPatrolPoint;
                    return(false);
                }

                var offset = controller.Position - hitCollider.transform.position;
                var dist   = Vector3.SqrMagnitude(offset);

                if (!(dist < minDist))
                {
                    continue;
                }

                controller.Target = hitCollider.gameObject;
                minDist           = dist;
            }

            return(controller.Target != null);
        }
예제 #11
0
#pragma warning disable CS0649

        /*****************************
        *         Variables         *
        *****************************/

#pragma warning restore CS0649

        /*****************************
        *           Init            *
        *****************************/

        /*****************************
        *          Update           *
        *****************************/

        /*****************************
        *          Methods          *
        *****************************/

        public override bool Evaluate(AiStateController controller)
        {
            return(controller.Target == null);
        }
예제 #12
0
#pragma warning disable CS0649

        /*****************************
        *         Variables         *
        *****************************/

#pragma warning restore CS0649

        /*****************************
        *          Methods          *
        *****************************/
        public abstract bool Evaluate(AiStateController controller);
예제 #13
0
#pragma warning disable CS0649

        /*****************************
        *         Variables         *
        *****************************/

#pragma warning restore CS0649

        /*****************************
        *           Init            *
        *****************************/

        /*****************************
        *          Update           *
        *****************************/

        /*****************************
        *          Methods          *
        *****************************/

        public override void Act(AiStateController controller)
        {
        }
예제 #14
0
#pragma warning disable CS0649

        /*****************************
        *         Variables         *
        *****************************/

#pragma warning restore CS0649

        /*****************************
        *           Init            *
        *****************************/

        /*****************************
        *          Update           *
        *****************************/

        /*****************************
        *          Methods          *
        *****************************/

        public override void Act(AiStateController controller)
        {
            controller.DestroySpell();
        }
예제 #15
0
#pragma warning disable CS0649

        /*****************************
        *         Variables         *
        *****************************/
        public abstract void Act(AiStateController controller);
예제 #16
0
#pragma warning restore CS0649

        /*****************************
        *           Init            *
        *****************************/

        /*****************************
        *          Update           *
        *****************************/

        /*****************************
        *          Methods          *
        *****************************/

        public override void Act(AiStateController controller)
        {
            Debug.Log(message, controller.gameObject);
        }
예제 #17
0
#pragma warning restore CS0649

        /*****************************
        *           Init            *
        *****************************/

        /*****************************
        *          Update           *
        *****************************/

        /*****************************
        *          Methods          *
        *****************************/

        public override void Act(AiStateController controller)
        {
            controller.TargetSpeed = targetSpeed;
        }