private IEnumerator InstantiateCity(InstantiationProgress progress) { var cityWidth = _game.Config.CellSize * _game.Config.CityWidth; var cityLength = _game.Config.CellSize * _game.Config.CityLength; _ground.localScale = new Vector3(cityWidth, 1, cityLength); var counter = 0; _cells = new CellView[_game.Config.CityWidth, _game.Config.CityLength]; for (int i = 0; i < _game.Config.CityWidth; i++) { for (int j = 0; j < _game.Config.CityLength; j++) { if (counter >= _cellsInstantiatedPerFrame) { progress.AddLoadedCells(counter); counter = 0; yield return(null); } var position = new Vector3( i * _game.Config.CellSize - cityWidth / 2 + _game.Config.CellSize / 2, 0.001f, j * _game.Config.CellSize - cityLength / 2 + _game.Config.CellSize / 2); var instance = Instantiate(_cellPrefab, position, Quaternion.identity, _cellsParent); instance.Init(_game.City.Cells[i, j]); _cells[i, j] = instance; ++counter; } } progress.AddLoadedCells(counter); }
public IProgress Create() { var instantiationProgress = new InstantiationProgress(_game.Config.CityLength * _game.Config.CityWidth); StartCoroutine(InstantiateCity(instantiationProgress)); return(instantiationProgress); }