public static void SaveCampaign() { string datapath = Application.persistentDataPath; ProgressSave savedGame = new ProgressSave(); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Path.Combine(datapath, saveFile)); bf.Serialize(file, savedGame); file.Close(); Debug.Log("Player progress saved!"); }
public static ProgressSave GetGameData() { string datapath = Application.persistentDataPath; if (!FileExistsInFiles()) { return(null); } BinaryFormatter bf = new BinaryFormatter(); FileStream str = File.Open(Path.Combine(datapath, saveFile), FileMode.Open); ProgressSave savedGame = (ProgressSave)bf.Deserialize(str); str.Close(); Debug.Log("Player progress loaded!"); return(savedGame); }
void LoadProgress() { ProgressSave cs = SaveLoadProgress.GetGameData(); if (cs != null) { Difficulty.dLevel = cs.difficulty; } Dictionary <string, Campaign> campaigns = FreshCampaigns(); //load fresh campaigns if file doesn't exist if (cs != null) { Dictionary <string, int> d = cs.savedCampaigns.GetDictionary(); //read each saved campaign progress foreach (string str in d.Keys) { //if we don't have this campaign anymore, keep going if (!campaigns.ContainsKey(str)) { Debug.LogError("Campaign in file no longer exists!"); continue; } //set campaign progress to whatever's saved campaigns[str].spot = d[str]; } } //load campaigns into manager CampaignManager.LoadCampaigns(campaigns); //save new campaign progress file if (cs == null) { SaveLoadProgress.SaveCampaign(); } }
private void Start() { PS = new ProgressSave(); }