private void GenerateWorldChunk() { worldChunks.Clear(); TileBase tile = null; OreData oreData = rockData; currentChunk = 0; for (int chunks = 0; chunks < chunksCount; chunks++) { WorldChunk chunk = new WorldChunk(); int yDepth = -Mathf.RoundToInt((worldChunks.Count) * chunkSize.y); chunk.StartDepth = yDepth; for (int x = 0; x < chunkSize.x; x++) { for (int y = yDepth; y > yDepth - chunkSize.y; y--) { if (x == 0 || x == chunkSize.x - 1 || y == yDepth - chunkSize.y - 1 || y == 0 && x < 10) { oreData = bedRockData; tile = bedRockData.tile; } else if (y > -5) { oreData = rockData; tile = groundTile; } else { float xCoord = (float)x * caveScale + seed; float yCoord = (float)y * caveScale + seed; float caveNoise = SimplePerlin(xCoord, yCoord, caveMultiplier, caveDivider); if (caveNoise < caveDensity) { tile = groundTile; xCoord = (float)x * oreScale + seed; yCoord = (float)y * oreScale + seed; float oreNoise = SimplePerlin(xCoord, yCoord, oreMultiplier, oreDivider); oreData = GetOreAtDensity(oreNoise, y); } else { oreData = null; tile = null; } } Vector3Int pos = new Vector3Int(x, y, 0); SetChunkTileData(chunk, tile, pos, oreData, "Underworld"); tile = null; } } worldChunks.Add(chunk); } }
void SetChunkTileData(WorldChunk chunk, TileBase tile, Vector3Int localPlace, OreData oreData, string biome) { float durability = 0; if (oreData != null) { durability = oreData.durability; } var worldTile = new WorldTile { LocalPlace = localPlace, WorldLocation = underworldMap.CellToWorld(localPlace), TileBase = tile, TilemapMember = underworldMap, WorldChunkMember = chunk, Name = localPlace.x + "," + localPlace.y, Ore = new OreTile(oreData, underworldOres), Ladder = new LadderTile(false, underworldLadders), Durability = durability, Biome = biome }; chunk.tiles.Add(worldTile); }
public OreTile(OreData oreData, Tilemap tilemap) { Data = oreData; TilemapMember = tilemap; }