//Translate the intData to tiles. private TileObject[,] ConvertToTiles(int[,] mapData) { TileObject[,] toReturn = new TileObject[viewPortRadius, viewPortRadius]; cachedTiles = new List <TileObject>(); for (int y = 0; y < viewPortRadius; y++) { for (int x = 0; x < viewPortRadius; x++) { int intData = mapData[x, y]; bool foundInCache = false; foreach (var cachedTile in cachedTiles) { if (cachedTile.id == intData) { if (cachedTile.tile == null) { Debug.Log("null cachedTileObject at: " + cachedTile.id); cachedTiles.Remove(cachedTile); break; } //Broken tile, fetch a new one toReturn[x, y] = cachedTile.Copy(); foundInCache = true; break; } } if (foundInCache) { continue; } TileObject fetched = TileAtlas.FetchTileObjectByID(intData); toReturn[x, y] = fetched.Copy(); cachedTiles.Add(fetched); } } return(toReturn); }
private void ReplaceTileOnChunk(Chunk chunkData, Vector2Int tilePos, Vector3Int viewPortPos, int idOfNewTile) { chunkData.mapData[tilePos.x, tilePos.y] = idOfNewTile; //Please work it's like 2am viewport.SetTile(viewPortPos, TileAtlas.FetchTileObjectByID(idOfNewTile).tile); }