WaveManager
Description:
This class manages enemy waves in the game. It keeps track of the number and type of enemies spawned and destroys them when needed. The class subscribes to various events such as player turn taken, game restart, and game end.
Fields and Properties
debugDontSpawnWaves
: A debugging field to prevent waves from spawning.Instance
: Singleton instance for global access.enemyList
: List storing available enemy prefabs.spawnedEnemies
: List storing instances of spawned enemies.enemyObjectPoolParent
: GameObject parent for enemy pooling.SpawnedEnemyTypes
: HashSet storing types of enemies that have been spawned.enemyWaves
: List storing wave data.enemiesSpawnedPerWave
: Dictionary mapping each wave to the number of enemies spawned for that wave.
Methods
Awake()
: Initializes singleton instance.Start()
: Initializes various functionalities and event handlers at the start.HandleStartMethods()
: Additional startup functionalities, mostly event subscription and setup.OnDestroy()
: Unsubscribes from player turn events.DestroyAllEnemies()
: Destroys all spawned enemy instances.OnTurnTaken(int)
: Executes when a player's turn is taken, responsible for spawning enemies.- Various
GeneratePositionXPattern
methods: Methods for generating spawn positions for enemies based on geometric shapes like Circle, Square, Triangle, Spiral, Pentagon, Wave, Grid. SpawnEnemy()
: Creates and initializes an enemy character.RegisterPoolIfItDoesntExist()
: Checks and registers an object pool if it does not exist for a given enemy type.
Observations:
- Singleton pattern is being used to make the class globally accessible. Ensure that the singleton initialization logic aligns well with Unity's object lifecycle.
- Events are heavily used to decouple the class from others.
- There is use of data structures like
List
,HashSet
, andDictionary
for maintaining various kinds of data.
Optimizations:
- Consider encapsulating the wave spawning logic into a smaller utility class to reduce the complexity and responsibilities of this class.
- Consider optimizing
DestroyAllEnemies()
by using pooling, as destroying and instantiating GameObjects is resource-intensive. - Opt for a single function with an enumeration parameter for the different position patterns, to reduce method count and increase maintainability.
Code Style:
- Commenting is present but inconsistent. Consider adding summary comments for all public methods for better readability.
- If you're using Unity's new input system, you can replace
[Button("Destroy All Enemies")]
with a native Unity UI button event.
Suggested Refactoring:
- Refactor the
OnTurnTaken()
method by breaking out smaller utility functions to handle enemy spawning logic.
Would you like to go over each class' documentation or move on to discussing other aspects of the game?