public void CreateChunk(int x, int y, int z) { WorldPos worldPos = new WorldPos(x, y, z); //Instantiate the chunk at the coordinates using the chunk prefab GameObject newChunkObject = Instantiate( chunkPrefab, new Vector3(x, y, z), Quaternion.Euler(Vector3.zero) ) as GameObject; Chunk newChunk = newChunkObject.GetComponent <Chunk>(); newChunkObject.name = "Chunk: " + x / 16f + ":" + y / 16f + ":" + z / 16f; newChunk.pos = worldPos; newChunk.world = this; //Add it to the chunks dictionary with the position as the key chunks.Add(worldPos, newChunk); bool HasLoadedChunk = false; if ((Network.isServer || (!Network.isServer && !Network.isClient)) && IsLoadChunks) { HasLoadedChunk = Serialization.Load(newChunk); } if (!HasLoadedChunk) { newChunk = MyTerrainGen.ChunkGen(newChunk); } newChunk.transform.parent = gameObject.transform; newChunk.SetBlocksUnmodified(); GetManager.GetZoneManager().LoadZones(new Vector3(x, y, z)); DebugChunksLoadedCount++; }
public void DestroyChunk(int x, int y, int z) { Chunk chunk = null; if (chunks.TryGetValue(new WorldPos(x, y, z), out chunk)) { // atm it is saved when it is removed if (SaveFileName == "") // if default then update to the game file name { SaveFileName = GetManager.GetGameManager().GameName; } DebugPolygonCount -= chunk.PolygonCount; Serialization.SaveChunk(chunk); Object.Destroy(chunk.gameObject); chunks.Remove(new WorldPos(x, y, z)); } GetManager.GetZoneManager().DestroyZonesInCubeNotCentred(new Vector3(x, y, z), new Vector3(Chunk.chunkSize, Chunk.chunkSize, Chunk.chunkSize)); DebugChunksLoadedCount--; }