//===================// //==================// //Saving and Loading// //==================// public void SaveGame() { BinaryFormatter formatter = new BinaryFormatter(); FileStream fileStream = File.Create(Application.persistentDataPath + "/baseInfo.dat"); GameData gameData = new GameData(); gameData.supplyStone = supplyStone; gameData.supplyWood = supplyWood; gameData.supplyFood = supplyFood; gameData.maxVillagers = maxVillagers; //Save Villagers foreach (BaseVillager villager in villagerList) { gameData.villagerList.Add(villager.Save()); } //Save Buildings foreach (BaseBuilding building in toBeBuilt) { gameData.toBeBuilt.Add(building.Save()); } foreach (BaseBuilding building in buildingList) { gameData.buildingList.Add(building.Save()); } foreach (BaseBuilding building in toBeUpgraded) { gameData.toBeUpgraded.Add(building.Save()); } //Save Inventory gameData.inventoryData = inventoryReference.Save(); //Save timer for next attack gameData.attackTimer = attackTimer; //Save quests foreach (Quest quest in GetComponent <QuestManager>().GetQuestList()) { gameData.questList.Add(quest.Save()); } formatter.Serialize(fileStream, gameData); fileStream.Close(); Debug.Log("Game Saved"); }