Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- public static class SaveSystem {
- public static void CheckDirectory() {
- if(!Directory.Exists(Application.dataPath + "/Saves/")) {
- Directory.CreateDirectory (Application.dataPath + "/Saves/");
- }
- }
- public static void SaveProgress (SaveGame save) {
- CheckDirectory ();
- BinaryFormatter formatter = new BinaryFormatter ();
- string path = Application.dataPath + "/Saves/player.save";
- FileStream stream = new FileStream (path, FileMode.Create);
- Progress data = new Progress (save);
- formatter.Serialize (stream, data);
- stream.Close ();
- }
- public static void Delete (string pathPart) {
- string path = Application.dataPath + "/Saves/" + pathPart + ".save";
- File.Delete(path);
- }
- public static Progress LoadProgress() {
- string path = Application.dataPath + "/Saves/player.save";
- if (File.Exists (path)) {
- BinaryFormatter formatter = new BinaryFormatter ();
- FileStream stream = new FileStream (path, FileMode.Open);
- Progress data = formatter.Deserialize (stream) as Progress;
- stream.Close ();
- return data;
- } else {
- Debug.LogError ("Save file for progress not found in " + path);
- return null;
- }
- }
- public static void SaveSettings (Menu menu) {
- CheckDirectory ();
- BinaryFormatter formatter = new BinaryFormatter ();
- string path = Application.dataPath + "/Saves/settings.save";
- FileStream stream = new FileStream (path, FileMode.Create);
- Settings data = new Settings (menu);
- formatter.Serialize (stream, data);
- stream.Close ();
- }
- public static Settings LoadSettings () {
- string path = Application.dataPath + "/Saves/settings.save";
- if (File.Exists (path)) {
- BinaryFormatter formatter = new BinaryFormatter ();
- FileStream stream = new FileStream (path, FileMode.Open);
- Settings data = formatter.Deserialize (stream) as Settings;
- stream.Close ();
- return data;
- } else {
- Debug.LogError ("Save file for settings not found in " + path);
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement