public void updateChunksToLoad() { //create a blank chunk list List <Chunk> newChunks = new List <Chunk>(); for (int i = ChunkHelpers.getRealtiveChunkCoord(player.transform.position) - (LookUpData.renderDisctance * LookUpData.chunkWidth); i <= ChunkHelpers.getRealtiveChunkCoord(player.transform.position) + (LookUpData.renderDisctance * LookUpData.chunkWidth); i += LookUpData.chunkWidth) { // get the chunk at this position Chunk newLoadedChunk = generateChunk(i); // set it to active if it is not newLoadedChunk.setLoadStatus(true); // add this chunk to the newly loaded chunks newChunks.Add(newLoadedChunk); } // go through all the loaded chunks in the last frame for (int i = 0; i < currentLoadedChunks.Count; i++) { // if the chunk is not in the new list of chunks to // load then set active to false (unloading) if (!newChunks.Contains(currentLoadedChunks[i])) { currentLoadedChunks[i].setLoadStatus(false); } } // set the current loaded chunks to the new list of chunks currentLoadedChunks = newChunks; }
public Chunk getChunk(Vector3 worldPosition) { Chunk found; // get what chunk is at this x position, if there is none then it is null chunks.TryGetValue(ChunkHelpers.getRealtiveChunkCoord(worldPosition), out found); return(found); }
public void Update() { // get the chunkX of the chunk that the player is in int playerChunkX = ChunkHelpers.getRealtiveChunkCoord(world.player.transform.position); // get the chunk variable of the chunkX Chunk playerChunk; world.chunks.TryGetValue(playerChunkX, out playerChunk); // set all the fields in the debug screen to the correct values playerX.SetText("" + Mathf.RoundToInt(world.player.transform.position.x)); playerY.SetText("" + Mathf.RoundToInt(world.player.transform.position.y)); chunk.SetText("" + playerChunk.chunkX); totalChunks.SetText("" + world.chunks.Count); biome.SetText("" + playerChunk.biomeRefrence.biome.biomeName); seed.SetText("" + world.seed); FPS.SetText("" + Mathf.RoundToInt(1 / Time.deltaTime)); }