public void InitMap(MapGenerationParameters genParams, Transform transform) { this.genParams = genParams; //Generate map info _mapInfo = mapGen.GetRandomMapInfo(genParams.seed, genParams.size); //Setup tile-drilling tileDrillDict = new Dictionary <Pos, float>(); //Generate chunk parameters int chunkAmount = mapInfo.size / mapInfo.chunkSize; _mapChunks = new MapChunk[chunkAmount, chunkAmount]; //Initialize chunk graphics-tile maps var graphicsGroundMap = MapGrahicsHelper.GetGraphicsGroundMap(mapInfo.groundMap); var graphicsBlockMap = MapGrahicsHelper.GetGraphicsBlockMap(mapInfo.blockMap); var graphicsGroundChunks = MapGrahicsHelper.SplitArray(graphicsGroundMap, chunkAmount); var graphicsBlockChunks = MapGrahicsHelper.SplitArray(graphicsBlockMap, chunkAmount); //Create chunks for (int x = 0; x < chunkAmount; x++) { for (int y = 0; y < chunkAmount; y++) { var chunkObj = PrefabLibrary.Create("MapChunk"); chunkObj.transform.SetParent(transform, false); chunkObj.GetComponent <MapChunk>().GenerateChunk(graphicsGroundChunks[x, y], graphicsBlockChunks[x, y], x * mapInfo.chunkSize, y * mapInfo.chunkSize, mapInfo.chunkSize); _mapChunks[x, y] = chunkObj.GetComponent <MapChunk>(); } } }
private void UpdateGraphicsTileAt(int x, int y) { int chunkSize = mapInfo.chunkSize; var block = mapInfo.GetBlockAt(x, y); var blockPos = new Pos(x / chunkSize, y / chunkSize); var tilePos = new Pos(x % chunkSize, y % chunkSize); var gfxBlock = MapGrahicsHelper.GetGraphicsBlockTile(mapInfo.blockMap, x, y, block); _mapChunks[blockPos.x, blockPos.y].ChangeBlockTile(tilePos.x, tilePos.y, gfxBlock); }