Beispiel #1
0
    void FixedUpdate()
    {
        if (!_initialized)
        {
            return;
        }

        if (!_isFighting)
        {
            return;
        }

        if (_state != FightingState.Idle)
        {
            return;
        }

        if (_currentTarget != null)
        {
            if (_currentTarget._state == FightingState.Dying)
            {
                _currentTarget = null;
            }
        }

        if (_currentTarget == null)
        {
            if (!_targetsQueue.TryDequeue(out _currentTarget))
            {
                return;
            }
        }

        StartHitting();
    }
Beispiel #2
0
    public void Dispose()
    {
        FightingSystem fs = null;

        while (TargetsQueue.TryDequeue(out fs))
        {
            fs.Died -= EnemyDied;
        }
    }
    public void Initialize(Vector3 startPosition, Vector3 endPosition)
    {
        _detectingSystem = gameObject.GetComponent <EnemyDetectingSystem>();
        _fightingSystem  = gameObject.GetComponent <FightingSystem>();
        _movementSystem  = gameObject.GetComponent <MovementSystem>();


        var           baseCreature = gameObject.GetComponent <BaseCreature>();
        CharacterInfo info;

        switch (baseCreature.race)
        {
        case Race.Agents:
        {
            var baseAgent = (BaseAgent)baseCreature;
            info = GameManager.instance.agentsInfoGetter.GetFor(baseAgent.type);
            break;
        }

        case Race.Aliens:
        {
            var baseAlien = (BaseAlien)baseCreature;
            info = GameManager.instance.aliensInfoGetter.GetFor(baseAlien.type);
            break;
        }

        default:
            throw new NotSupportedException($"Race {baseCreature.race:F} not supported");
        }

        var animator = gameObject.GetComponentInChildren <Animator>();

        _detectingSystem.Initialize(baseCreature.race);
        var queue = _detectingSystem.TargetsQueue;

        _fightingSystem.Initialize(queue, info.health, info.damage, animator);

        var transform = gameObject.GetComponent <Transform>();

        _movementSystem.Initialize(transform, startPosition, endPosition, info.speed, animator);

        _detectingSystem.EnemyDetected     += DetectingSystemOnEnemyDetected;
        _detectingSystem.NoEnemiesAround   += DetectingSystemOnNoEnemiesAround;
        _fightingSystem.AfterAnimationDied += FightingSystemOnAfterAnimationDied;

        _state = State.Moving;
        _movementSystem.Enable();
    }