/// <summary> /// 创建一键生成文件 /// </summary> /// <param name="creatorAPI"></param> /// <param name="directory"></param> /// <param name="path"></param> /// <param name="Start"></param> /// <param name="End"></param> /// <param name="position"></param> public static void CreateOnekey(CreatorAPI creatorAPI, string directory, string path, Point3 Start, Point3 End, Point3 position) { int count = 0; CreatorMain.Math.StartEnd(ref Start, ref End); FileStream fileStream = new FileStream(directory + "/" + path, FileMode.Create); EngineBinaryWriter binaryWriter = new EngineBinaryWriter(fileStream, true); binaryWriter.Write(End.X - position.X); binaryWriter.Write(End.Y - position.Y); binaryWriter.Write(End.Z - position.Z); binaryWriter.Write(Start.X - position.X); binaryWriter.Write(Start.Y - position.Y); binaryWriter.Write(Start.Z - position.Z); for (int x = End.X; x <= Start.X; x++) { for (int y = End.Y; y <= Start.Y; y++) { for (int z = End.Z; z <= Start.Z; z++) { binaryWriter.Write(GameManager.Project.FindSubsystem <SubsystemTerrain>(true).Terrain.GetCellValueFast(x, y, z)); count++; } } } binaryWriter.Dispose(); fileStream.Dispose(); creatorAPI.componentMiner.ComponentPlayer.ComponentGui.DisplaySmallMessage($"创建一键生成成功,共{count}个方块", true, true); }
public static void ImportCopywMod(string path, string importFile) { List <string> list = new List <string>(); Stream stream = File.OpenRead(importFile); StreamReader streamReader = new StreamReader(stream); string text = streamReader.ReadToEnd(); streamReader.Dispose(); stream.Dispose(); foreach (string data in text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)) { list.Add(data); } FileStream fileStream = new FileStream(path, FileMode.Create); EngineBinaryWriter binaryWriter = new EngineBinaryWriter(fileStream, true); string[] data2 = list[0].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); int MaxX = int.Parse(data2[0]); int MaxY = int.Parse(data2[1]); int MaxZ = int.Parse(data2[2]); list.RemoveAt(0); binaryWriter.Write(MaxX); binaryWriter.Write(MaxY); binaryWriter.Write(MaxZ); for (int x = 0; x <= MaxX; x++) { for (int y = 0; y <= MaxY; y++) { for (int z = 0; z <= MaxZ; z++) { int blockID = 0; for (int i = 0; i < list.Count; i++) { string[] database = list[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (int.Parse(database[0]) == x && int.Parse(database[1]) == y && int.Parse(database[2]) == z) { blockID = int.Parse(database[3]); list.RemoveAt(i); } } binaryWriter.Write(blockID); } } } binaryWriter.Dispose(); fileStream.Dispose(); }
/// <summary> /// 普通文本文件导入 /// </summary> /// <param name="path"></param> /// <param name="importFile"></param> public static void ImportOnekeyoMod2(string path, string importFile) { List <string> list = new List <string>(); Stream stream = File.OpenRead(importFile); StreamReader streamReader = new StreamReader(stream); string text = streamReader.ReadToEnd(); streamReader.Dispose(); stream.Dispose(); FileStream fileStream = new FileStream(path, FileMode.Create); EngineBinaryWriter binaryWriter = new EngineBinaryWriter(fileStream, true); foreach (string data in text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)) { binaryWriter.Write(int.Parse(data)); } binaryWriter.Dispose(); fileStream.Dispose(); }
public static void Coppy_zone(string path, Point3 Point1, Point3 Point2, SubsystemTerrain subsystemTerrain, ComponentPlayer player) { int startX = Math.Min(Point1.X, Point2.X); int endX = Math.Max(Point1.X, Point2.X); int startY = Math.Min(Point1.Y, Point2.Y); int endY = Math.Max(Point1.Y, Point2.Y); int startZ = Math.Min(Point1.Z, Point2.Z); int endZ = Math.Max(Point1.Z, Point2.Z); FileStream fileStream = new FileStream(path, FileMode.Create); EngineBinaryWriter engineBinaryWriter = new EngineBinaryWriter((Stream)fileStream, true); engineBinaryWriter.Write((byte)79); engineBinaryWriter.Write((byte)110); engineBinaryWriter.Write((byte)101); engineBinaryWriter.Write((byte)75); engineBinaryWriter.Write((byte)101); engineBinaryWriter.Write((byte)121); engineBinaryWriter.Write((byte)0); engineBinaryWriter.Write(0); blockCount = 0; BlockList.Clear(); for (int x = 0; x <= endX - startX; x++) { for (int y = 0; y <= endY - startY; y++) { for (int z = 0; z <= endZ - startZ; z++) { BlockMem blmem = new BlockMem(); int X, Y, Z; if (Point1.X > Point2.X) { blmem.x = -x; X = Point1.X - x; } else { blmem.x = x; X = Point1.X + x; } if (Point1.Y > Point2.Y) { blmem.y = -y; Y = Point1.Y - y; } else { blmem.y = y; Y = Point1.Y + y; } if (Point1.Z > Point2.Z) { blmem.z = -z; Z = Point1.Z - z; } else { blmem.z = z; Z = Point1.Z + z; } blmem.id = subsystemTerrain.Terrain.GetCellValueFast(X, Y, Z); engineBinaryWriter.Write(blmem.x); engineBinaryWriter.Write(blmem.y); engineBinaryWriter.Write(blmem.z); engineBinaryWriter.Write(blmem.id); ++blockCount; BlockList.Add(blmem); blockCount++; } } } player.ComponentGui.DisplaySmallMessage(string.Format("Sucsses {0} place blocks", blockCount), true, true); engineBinaryWriter.BaseStream.Position = 7L; engineBinaryWriter.Write(blockCount); engineBinaryWriter.Dispose(); fileStream.Dispose(); }