private void ReplaceChunkPrefabs(Index index) { if (CacheChunkIndexes.Exists(p => p.IsEqual(index)) == true) { return; } Chunk chunk = ChunkManager.GetChunkComponent(index); if (chunk != null) { int SideLength = Engine.ChunkSideLength; for (int x = 0; x < SideLength; x++) { for (int y = 0; y < SideLength; y++) ///高度 { for (int z = 0; z < SideLength; z++) { // 循环创建chunk中每一个Voxel ushort data = chunk.GetVoxelSimple(x, y, z); if (data > 100 && data <= 200) { ushort span = 100; chunk.SetVoxel(x, y, z, (ushort)(data + span), true); } } } } CacheChunkIndexes.Add(index); } }
private void ReplaceChunkDatas(Index index) { Chunk chunk = ChunkManager.GetChunkComponent(index); if (chunk != null) { for (int i = 0; i < chunk.transform.childCount; i++) { DestroyObject(chunk.transform.GetChild(i).gameObject); } int SideLength = Engine.ChunkSideLength; for (int x = 0; x < SideLength; x++) { for (int y = 0; y < SideLength; y++) ///高度 { for (int z = 0; z < SideLength; z++) { // 循环创建chunk中每一个Voxel ushort data = chunk.GetVoxelSimple(x, y, z); if (data > 200) { ushort span = 100; chunk.SetVoxel(x, y, z, (ushort)(data - span), true); } } } } if (CacheChunkIndexes.Exists(p => p.IsEqual(index)) == true) { CacheChunkIndexes.Remove(index); } } }
public static string CompressData(Chunk chunk) { // returns the data of chunk in compressed string format StringWriter writer = new StringWriter(); int i = 0; int length = chunk.GetDataLength(); // length of VoxelData array ushort currentCount = 0; // count of consecutive voxels of the same type ushort currentData = 0; // data of the current voxel for (i = 0; i < length; i++) { // for each voxel ushort thisData = chunk.GetVoxelSimple(i); // read raw data at i if (thisData != currentData) { // if the data is different from the previous data, write the last block and start a new one // write previous block if (i != 0) { // (don't write in the first loop iteration, because count would be 0 (no previous blocks)) writer.Write((char)currentCount); writer.Write((char)currentData); } // start new block currentCount = 1; currentData = thisData; } else { // if the data is the same as the last data, simply add to the count currentCount++; } if (i == length - 1) { // if this is the last iteration of the loop, close and write the current block writer.Write((char)currentCount); writer.Write((char)currentData); } } string compressedData = writer.ToString(); writer.Flush(); writer.Close(); return(compressedData); }
public static Dictionary<string, string> TempChunkData; // stores chunk's data to write into a region file later #endregion Fields #region Methods public static string CompressData( Chunk chunk ) { // returns the data of chunk in compressed string format StringWriter writer = new StringWriter(); int i = 0; int length = chunk.GetDataLength(); // length of VoxelData array ushort currentCount = 0; // count of consecutive voxels of the same type ushort currentData = 0; // data of the current voxel for (i=0; i<length; i++) { // for each voxel ushort thisData = chunk.GetVoxelSimple(i); // read raw data at i if (thisData != currentData) { // if the data is different from the previous data, write the last block and start a new one // write previous block if (i != 0) { // (don't write in the first loop iteration, because count would be 0 (no previous blocks)) writer.Write ((char)currentCount); writer.Write ((char)currentData); } // start new block currentCount = 1; currentData = thisData; } else { // if the data is the same as the last data, simply add to the count currentCount ++; } if (i == length-1) { // if this is the last iteration of the loop, close and write the current block writer.Write ((char)currentCount); writer.Write ((char)currentData); } } string compressedData = writer.ToString(); writer.Flush (); writer.Close (); return compressedData; }