/// <summary> /// Saves the root chunk buffer to the persistent data storage slot. /// Saving multiple chunk buffers is not yet included /// </summary> /// <param name="id"></param> public void SaveChunkBufferToSlot(int id) { if (DoChunks()) { Debug.LogWarning("Saving / Loading multiple chunk buffers doesn't work yet :( "); return; } if (File.Exists(Application.persistentDataPath + "/fogData" + id.ToString() + ".dat")) { BinaryFormatter newFormatter = new BinaryFormatter(); FileStream fl = File.Open(Application.persistentDataPath + "/fogData" + id.ToString() + ".dat", FileMode.Open); MangoBufferData data = new MangoBufferData(chunks[trueRootChunkPosition].GetRevealedBuffer()); newFormatter.Serialize(fl, data); Debug.Log("Saved current buffer to slot " + id.ToString()); fl.Close(); } else { BinaryFormatter newFormatter = new BinaryFormatter(); FileStream fl = File.Create(Application.persistentDataPath + "/fogData" + id.ToString() + ".dat"); MangoBufferData data = new MangoBufferData(chunks[trueRootChunkPosition].GetRevealedBuffer()); newFormatter.Serialize(fl, data); Debug.Log("Created and saved current buffer to slot " + id.ToString()); fl.Close(); } }
/// <summary> /// Loads the persistent data storage slot to the root chunk buffer. /// Loading to multiple chunk buffers is not yet included /// </summary> /// <param name="id"></param> public void LoadSlotBufferToChunk(int id) { if (DoChunks()) { Debug.LogWarning("Saving / Loading multiple chunk buffers doesn't work yet :( "); return; } if (File.Exists(Application.persistentDataPath + "/fogData" + id.ToString() + ".dat")) { BinaryFormatter newFormatter = new BinaryFormatter(); FileStream fl = File.Open(Application.persistentDataPath + "/fogData" + id.ToString() + ".dat", FileMode.Open); MangoBufferData data = (MangoBufferData)newFormatter.Deserialize(fl); chunks[trueRootChunkPosition].SetRevealedBuffer(data.buffer); Debug.Log("Loaded buffer from slot " + id.ToString() + " to current "); fl.Close(); } else { Debug.LogError("The requested storage slot does not yet exist."); } }