/* * Loads a new chunk from file with tiles and objects at desired position */ public void LoadChunkAt(int x, int y) { if (!chunks.ContainsKey(new Vector2(x, y))) { SaveLoadData saveLoadData = new SaveLoadData(); var savedChunk = saveLoadData.LoadChunk(x, y, worldName); if (savedChunk != null) { //Creates an empty gameobject chunk to store the tiles var chunkGO = Instantiate(chunkEmptyObject, new Vector3(x, y, 0), Quaternion.identity, transform); var newChunk = chunkGO.GetComponent <Chunk>(); chunkGO.name = "Chunk(" + x + "," + y + ")"; //Fills the chunk class component on the chunk GO newChunk.size = savedChunk.size; newChunk.posX = savedChunk.posX; newChunk.posY = savedChunk.posY; newChunk.tiles = savedChunk.tiles; newChunk.objects = savedChunk.objects; //Creates the tiles on the chunk CreateLayers(newChunk); //Adds chunk to the total list of chunks chunks.Add(new Vector2(x, y), newChunk); } } }