public GameObject PositionToChunk(Vector3 position) { Index chunkIndex = new Index(Mathf.RoundToInt(position.x / ChunkScale.x) / ChunkSideLength, Mathf.RoundToInt(position.y / ChunkScale.y) / ChunkSideLength, Mathf.RoundToInt(position.z / ChunkScale.z) / ChunkSideLength); return(ChunkManager.GetChunk(chunkIndex)); }
public static GameObject SpawnChunk(Index index) // spawns a single chunk (only if it's not already spawned) { GameObject chunk = ChunkManager.GetChunk(index); if (chunk == null) { return(MasterEngine.getInstance().ChunkManagerInstance.DoSpawnChunk(index)); } else { return(chunk); } }
public void ReceiveChangeBlock(NetworkPlayer sender, int x, int y, int z, int chunkx, int chunky, int chunkz, int data) // receives a change sent by other client or server { GameObject chunkObject = ChunkManager.GetChunk(chunkx, chunky, chunkz); if (chunkObject != null) { // convert back to VoxelInfo Index voxelIndex = new Index(x, y, z); BlockInfo info = new BlockInfo(voxelIndex, chunkObject.GetComponent <Chunk>()); // apply change Voxel.ChangeBlockMultiplayer(info, (ushort)data, sender); } }
public void ReceiveVoxelData(int chunkx, int chunky, int chunkz, byte[] data) { GameObject chunkObject = ChunkManager.GetChunk(chunkx, chunky, chunkz); // find the chunk if (chunkObject == null) { return; // abort if chunk isn't spawned anymore } Chunk chunk = chunkObject.GetComponent <Chunk>(); ChunkDataFiles.DecompressData(chunk, GetString(data)); // decompress data // ChunkManager.DataReceivedCount ++; // let ChunkManager know that we have received the data chunk.VoxelsDone = true; // let Chunk know that it can update it's mesh Chunk.CurrentChunkDataRequests--; }
public static GameObject SpawnChunkFromServer(Index index) // spawns a chunk and disables mesh generation and enables timeout (used by the server in multiplayer) { GameObject chunk = ChunkManager.GetChunk(index); if (chunk == null) { chunk = MasterEngine.getInstance().ChunkManagerInstance.DoSpawnChunk(index); Chunk chunkComponent = chunk.GetComponent <Chunk>(); chunkComponent.EnableTimeout = true; chunkComponent.DisableMesh = true; return(chunk); } else { return(chunk); // don't disable mesh generation and don't enable timeout for chunks that are already spawned } }