public void InitializeMap() { gridMapSize = GridPoints.UnityToGridCoord(unityMapSize); tilesInMap = new GameObject[unityMapSize.x, unityMapSize.y]; mapTiles = new GameObject[unityMapSize.x, unityMapSize.y, 16]; //array with all tiles GetSeed(); }
public void CombineTilesInMap() { for (int x = 1; x < unityMapSize.x; x++) { for (int y = 1; y < unityMapSize.y; y++) { if (tilesInMap[x, y] != null) { CombineTiles(tilesInMap[x, y], GridPoints.UnityToGridCoord(new Vector2(x, y))); } } } }
public void CreateTile(Tile tile, int xCoord, int yCoord) { Vector2 coords = new Vector2(xCoord, yCoord); GridPoints gridCoords = GridPoints.UnityToGridCoord(coords); if (IsInsideBoundaries(coords) && !TileAlreadyThere(gridCoords, tile.isGroundTile)) { GameObject tileToAdd = new GameObject("Tile", typeof(SpriteRenderer), typeof(TileObject)); tileToAdd.transform.position = new Vector3(gridCoords.x, gridCoords.y, 0f); // to render the sprites correctly SpriteRenderer spriteRenderer = tileToAdd.GetComponent <SpriteRenderer>(); spriteRenderer.material = pixelMaterial; TileObject tileData = tileToAdd.GetComponent <TileObject>(); tileData.tile = tile; tileToAdd.transform.parent = mapHolder.transform; tilesInMap[xCoord, yCoord] = tileToAdd; lastCreatedTile = tileToAdd; } }