using System.Collections; using System.Collections.Generic; using UnityEngine; public class WaveObserver : Singleton { private List _subjects = new List(); private List _copyConstantSpawn; private LevelConfig _levelConfig; public LevelConfig LevelConfig { set { _levelConfig = value; _copyConstantSpawn = new List(); foreach (EnemyType enemy in _levelConfig.ConstantSpawn) { _copyConstantSpawn.Add(enemy.Count); } } } public void Attach(SpawnerTile spawnerSubject) { spawnerSubject.Prefab = _levelConfig.GetRandomSpawn().GetEnemyObject(); spawnerSubject.InitialSpawnSpeed(_levelConfig.GetInterval()); _subjects.Add(spawnerSubject); } public void NotifySpawned(SpawnerTile spawnerSubject) { if (spawnerSubject.Prefab.Equals(_levelConfig.ConstantSpawn[0].GetEnemyObject())) { int currentCount = 0; for (int i = 0; i < _copyConstantSpawn.Count; i++) { if(_levelConfig.ConstantSpawn[i].GetEnemyObject() == spawnerSubject.Prefab) { currentCount = _copyConstantSpawn[i]--; break; } } if (currentCount <= 0) { foreach (SpawnerTile spawner in _subjects) { if (spawner.Prefab.Equals(spawnerSubject.Prefab)) { spawner.StopSpawn(); } } } } } }