GameData LoadGame(int saveSlot) { string path = Application.persistentDataPath + Path.DirectorySeparatorChar + "SaveData" + Path.DirectorySeparatorChar + "save" + saveSlot + ".gd"; SaveChainData.Load("chain" + saveSlot); if (File.Exists(path)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(path, FileMode.Open); GameData gd = (GameData)bf.Deserialize(file); file.Close(); coins = gd.totalCoins; keys = gd.totalKeys; return(gd); } return(new GameData()); }
// Save/Load void SaveGame() { SaveSettings(); if (gameData == null) { return; } if (!File.Exists(Application.persistentDataPath + Path.DirectorySeparatorChar + "SaveData")) { Directory.CreateDirectory(Application.persistentDataPath + Path.DirectorySeparatorChar + "SaveData"); } string path = Application.persistentDataPath + Path.DirectorySeparatorChar + "SaveData" + Path.DirectorySeparatorChar + "save" + gameData.saveSlot + ".gd"; SaveChainData.Save("chain" + gameData.saveSlot); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(path); bf.Serialize(file, gameData); file.Close(); }
private void OnDisable() { SaveChainData.Load("OriginalChainData"); }
void Start() { triggers = Resources.LoadAll <ChainTrigger>("ChainResources/Triggers"); SaveChainData.Save("OriginalChainData"); }