public void SaveGameData(GameData gameData) { string path = Application.persistentDataPath + "/gameData.data"; GameDataBinary gameDataBinary = GameDataBinary.InitWithGameData(gameData); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(path); bf.Serialize(file, gameDataBinary); file.Close(); Debug.Log("Game Saved"); }
public GameData LoadGameData() { string path = Application.persistentDataPath + "/gameData.data"; if (File.Exists(path)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(path, FileMode.Open); GameDataBinary gameDataBinary = (GameDataBinary)bf.Deserialize(file); Debug.Log("Game Loaded"); return(gameDataBinary.ConvertGameData()); } Debug.Log("No Load Files, Creating New Game Data"); return(new GameData()); }