public void GenerateWorld(WorldController worldController, int seed = -1) { if (seed != -1) { Random.InitState(seed); } _tileIdentifier = new TileIdentifier(_tileTypes); int minimumDepthForCurrentLayer = -_layers[0].Depth; int maximumDepthForCurrentLayer = -_layers[0].Depth; TilemapCollider2D surfaceCollider = _surfaceTilemap.GetComponent <TilemapCollider2D>(); int worldWidth = Mathf.RoundToInt(surfaceCollider.bounds.size.x); _worldInfo.HorizontalBorders = new Vector2Int(Mathf.RoundToInt(surfaceCollider.transform.position.x), Mathf.RoundToInt(surfaceCollider.transform.position.x) + worldWidth); int totalDepth = -_layers.Sum(x => x.Depth) - _layers[0].Depth; _worldInfo.VerticalBorders = new Vector2Int(_ceilHeight, totalDepth); _worldInfo.LoadableGridHorizontalRange = _worldInfo.HorizontalBorders; _worldInfo.LoadableGridVerticalRange = new Vector2(totalDepth + 1, -1); TilemapData tilemapData = new TilemapData(worldWidth, Mathf.Abs(totalDepth), maximumDepthForCurrentLayer); Camera mainCamera = Camera.main; for (int x = _worldInfo.HorizontalBorders.x; x < _worldInfo.HorizontalBorders.y; ++x) { _surfaceTilemap.SetTile(new Vector3Int(x, _ceilHeight, 0), _tileEdges.ClasifiedTiles[13]); _surfaceTilemap.SetTile(new Vector3Int(x, totalDepth + 1, 0), _tileEdges.ClasifiedTiles[13]); } for (int y = _ceilHeight; y > totalDepth; --y) { _surfaceTilemap.SetTile(new Vector3Int(_worldInfo.HorizontalBorders.x - 1, y, 0), _tileEdges.ClasifiedTiles[13]); _surfaceTilemap.SetTile(new Vector3Int(_worldInfo.HorizontalBorders.y, y, 0), _tileEdges.ClasifiedTiles[13]); } _tilemapController.AddTilemap(_surfaceTilemap, -_layers[0].Depth); _tilemapController.AddTilemap(_undergroundTilemap, totalDepth); GenerateSurface(tilemapData, _worldInfo.HorizontalBorders.x, _worldInfo.HorizontalBorders.y, minimumDepthForCurrentLayer, minimumDepthForCurrentLayer - _layers[0].Depth); maximumDepthForCurrentLayer -= _layers[0].Depth; _surfaceLayerBorders.Initialize(_layers[0]); for (int i = 1; i < _layers.Count; ++i) //all layers except surface layer (so the loop iterates from 1) { minimumDepthForCurrentLayer = maximumDepthForCurrentLayer; //minimum depth is maximum depth from previous layer maximumDepthForCurrentLayer -= _layers[i].Depth; LayerBorders borders = Instantiate(_layerBordersPrefab, _grid.transform); borders.Initialize(_layers[i], minimumDepthForCurrentLayer, worldWidth); GenerateLayer(tilemapData, _layers[i], _worldInfo.HorizontalBorders.x, _worldInfo.HorizontalBorders.y, minimumDepthForCurrentLayer, maximumDepthForCurrentLayer); } worldController.Initialize(tilemapData); }
private void Awake() { _tileIdentifier = new TileIdentifier(_tiles); }
public void Initialize(TilemapData data, TileIdentifier identifier) { _data = data; _tileIdentifier = identifier; _tilemapLoader.Initialize(this); }