Exemplo n.º 1
0
        IEnumerator Spawn()
        {
            for (int i = 0; i < m_waves.Length; i++)
            {
                m_currentWaveNumber.Value = i + 1;
                bool isLastWave = i == (m_waves.Length - 1);
                for (int j = 0; j < m_waves[i].EnemiesCount; j++)
                {
                    bool       isLastEnemy = (j == (m_waves[i].EnemiesCount - 1));
                    int        length      = m_waves[i].EnemyPrefabs.Length;
                    GameObject enemy       = Instantiate(m_waves[i].EnemyPrefabs[UnityEngine.Random.Range(0, length)]);
                    EnemyModel enemyModel  = enemy.GetComponent <EnemyModel>();
                    if (enemyModel != null)
                    {
                        IDisposable d = enemyModel.OnDead.Subscribe(OnUnitDead);
                        m_enemies.Add(enemyModel, d);
                        m_enemiesCount.Value = m_enemies.Count;
                    }
                    IMovable enemyMovable = enemy.GetComponent <IMovable>();
                    enemyMovable?.Move();

                    if (!isLastEnemy)
                    {
                        yield return(new WaitForSeconds(UnityEngine.Random.Range(m_waves[i].MinSpawnDelay, m_waves[i].MaxSpawnDelay)));
                    }
                }
                if (!isLastWave)
                {
                    yield return(new WaitForSeconds(m_waves[i].WaveDelay));
                }
            }

            m_spawnFinished.Value = true;
        }
Exemplo n.º 2
0
 private void RemoveTarget(EnemyModel target)
 {
     if (m_targets.TryGetValue(target, out IDisposable disposable))
     {
         m_targets.Remove(target);
         disposable?.Dispose();
     }
 }
Exemplo n.º 3
0
        private void OnTriggerExit(Collider target)
        {
            EnemyModel hittable = target.GetComponent <EnemyModel>();

            if (hittable != null)
            {
                RemoveTarget(hittable);
            }
        }
Exemplo n.º 4
0
        private void OnUnitDead(EnemyModel enemy)
        {
            if (m_enemies.ContainsKey(enemy))
            {
                IDisposable d = m_enemies[enemy];
                d.Dispose();
                m_enemies.Remove(enemy);
            }

            m_enemiesCount.Value = m_enemies.Count;
        }
Exemplo n.º 5
0
        private void OnTriggerEnter(Collider target)
        {
            EnemyModel enemyModel = target.GetComponent <EnemyModel>();

            if (enemyModel != null)
            {
                IDisposable dyingDisposable = enemyModel.OnDead.Subscribe(OnEnemyDead);
                m_targets.Add(enemyModel, dyingDisposable);
                if (!m_isReloading)
                {
                    Attack();
                }
            }
        }
Exemplo n.º 6
0
 private void OnEnemyDead(EnemyModel target)
 {
     Debug.Log($"OnUnitDying {target}");
     RemoveTarget(target);
 }