public bool loadgame(int id)//加载存档函数 { if (File.Exists(path + id)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(path + id, FileMode.Open); SaveBuild save = (SaveBuild)bf.Deserialize(file); file.Close(); Vector3i posTemp = new Vector3i(); foreach (Chunkpos pos in save.chunkkey) { posTemp.x = pos.x; posTemp.y = pos.y; posTemp.z = pos.z; ChunkBuild chunkTemp = MapBuild.Instance.GetChunk(posTemp); for (int x = 0; x < ChunkBuild.width; x++) { for (int y = 0; y < ChunkBuild.height; y++) { for (int z = 0; z < ChunkBuild.width; z++) { chunkTemp.blocks[x, y, z] = pos.blockType[x * 256 + y * 16 + z]; } } } chunkTemp.CreateMesh(); } return(true); } else { Debug.Log("No game saved!"); return(false); } }
public SaveBuild createSave() { SaveBuild save = new SaveBuild(); Chunkpos chunkTemp = new Chunkpos(); save.mapID = DateTime.Now + ""; foreach (ChunkBuild chunk in MapBuild.Instance.chunks.Values) { chunkTemp.x = chunk.position.x; chunkTemp.y = chunk.position.y; chunkTemp.z = chunk.position.z; chunkTemp.blockType = new List <byte>(); for (int x = 0; x < ChunkBuild.width; x++) { for (int y = 0; y < ChunkBuild.height; y++) { for (int z = 0; z < ChunkBuild.width; z++) { chunkTemp.blockType.Add(chunk.blocks[x, y, z]); } } } save.chunkkey.Add(chunkTemp); } return(save); }
public void savegame(int id) { SaveBuild save = createSave(); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(path + id); bf.Serialize(file, save); file.Close(); }
public string mapIDSaved(int id) { if (File.Exists(path + id)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(path + id, FileMode.Open); SaveBuild save = (SaveBuild)bf.Deserialize(file); file.Close(); return(save.mapID); } else { return("No Saved!"); } }