Advertisement
OK11

saveLoad

Nov 16th, 2020
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. public class SaveLoad
  2. {
  3.     public static void Save()
  4.     {
  5.         SaveData currentSave = new SaveData();
  6.         //
  7.         //assign currentSave fields
  8.         //
  9.         BinaryFormatter BF = new BinaryFormatter();
  10.         FileStream FS = File.Open(Application.persistentDataPath + "/SaveData.dat", FileMode.OpenOrCreate);
  11.         BF.Serialize(FS, currentSave);
  12.         FS.Close();
  13.     }
  14.     public static bool Load()
  15.     {
  16.         if (File.Exists(Application.persistentDataPath + "/SaveData.dat"))
  17.         {
  18.             BinaryFormatter BF = new BinaryFormatter();
  19.             FileStream FS = File.Open(Application.persistentDataPath + "/SaveData.dat", FileMode.Open);
  20.             SaveData currentLoad = (SaveData)BF.Deserialize(FS);
  21.             FS.Close();
  22.             //
  23.             //read currentLoad fields
  24.             //
  25.             return true;
  26.         }
  27.         else
  28.         {
  29.             return false;
  30.         }
  31.     }
  32.     [Serializable]
  33.     private class SaveData
  34.     {
  35.         //any serializable fields
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement