/// <summary> /// Creates all pools for the spawner. /// </summary> void Start() { MatchController.RegisterOnPause(Pause); MatchController.RegisterOnResume(Resume); _obstacleFactory = gameObject.GetComponent <IObstacleFactory>(); if (_obstacleFactory == null) { throw new Exception("Error: Obstacle factory not found! You must provide a script that inherits after IObstacleFactory!"); } var newPool = new ObstaclesPool(ObstacleTypeEnum.EnergyBlock, _obstacleFactory, _maxObstaclesPerPool, _startingObstaclesPerPool); _enemiesPools.Add(ObstacleTypeEnum.EnergyBlock, newPool); newPool = new ObstaclesPool(ObstacleTypeEnum.PhysicalBlock, _obstacleFactory, _maxObstaclesPerPool, _startingObstaclesPerPool); _enemiesPools.Add(ObstacleTypeEnum.PhysicalBlock, newPool); }
/// <summary> /// Creates new obstacles pool. If maxObstacles is smaller than startingObstaclesAmount - the latter will /// have assigned the value of the first one. /// </summary> /// <param name="obstacleTypeEnum">Type of the obstacle that this pool will be storing.</param> /// <param name="obstacleFactory">Factory used to create the obstacles.</param> /// <param name="maxObstacles">Maximal amount of obstacles this pool can store.</param> /// <param name="startingObstaclesAmount">Starting amount of obstacles that will be instantly ready.</param> public ObstaclesPool(ObstacleTypeEnum obstacleTypeEnum, IObstacleFactory obstacleFactory, int maxObstacles, int startingObstaclesAmount) { if (maxObstacles < startingObstaclesAmount) { startingObstaclesAmount = maxObstacles; } StoredObstaclesType = obstacleTypeEnum; _obstacleFactory = obstacleFactory; MaxObstacles = maxObstacles; BeginningObstacles = startingObstaclesAmount; int beginningObstaclesCount = MaxObstacles > BeginningObstacles ? BeginningObstacles : MaxObstacles; var obstacleData = new ObstacleIniData(); for (int i = 0; i < beginningObstaclesCount; i++) { AddNewObstacle(obstacleData); _obstaclesInUse++; } }