Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SaveLoad
- {
- public static void Save()
- {
- SaveData currentSave = new SaveData();
- //
- //assign currentSave fields
- //
- BinaryFormatter BF = new BinaryFormatter();
- FileStream FS = File.Open(Application.persistentDataPath + "/SaveData.dat", FileMode.OpenOrCreate);
- BF.Serialize(FS, currentSave);
- FS.Close();
- }
- public static bool Load()
- {
- if (File.Exists(Application.persistentDataPath + "/SaveData.dat"))
- {
- BinaryFormatter BF = new BinaryFormatter();
- FileStream FS = File.Open(Application.persistentDataPath + "/SaveData.dat", FileMode.Open);
- SaveData currentLoad = (SaveData)BF.Deserialize(FS);
- FS.Close();
- //
- //read currentLoad fields
- //
- return true;
- }
- else
- {
- return false;
- }
- }
- [Serializable]
- private class SaveData
- {
- //any serializable fields
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement