Skip to content

Instantly share code, notes, and snippets.

@moon-goon
Created April 13, 2016 10:36
Show Gist options
  • Save moon-goon/7b3d21496d27e7b60268dcfa7b38753e to your computer and use it in GitHub Desktop.
Save moon-goon/7b3d21496d27e7b60268dcfa7b38753e to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public static class SaveLoad {
public static List<Game> savedGames = new List<Game>();
public static void Save() {
SaveLoad.savedGames.Add(Game.current);
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Create (Application.persistentDataPath + "/savedGames.gd");
bf.Serialize(file, SaveLoad.savedGames);
file.Close();
}
public static void Load() {
if(File.Exists(Application.persistentDataPath + "/savedGames.gd")) {
BinaryFormatter bf = new BinaryFormatter();
FileStream file = File.Open(Application.persistentDataPath + "/savedGames.gd", FileMode.Open);
SaveLoad.savedGames = (List<Game>)bf.Deserialize(file);
file.Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment