public static void SaveToGraveyard() { BinaryFormatter formatter = new BinaryFormatter(); string savePath = Application.persistentDataPath + "/save.dat"; //If save file exists if (File.Exists(savePath)) { //Load the save and store in variable SaveData save = LoadGame(); var currentTime = System.DateTime.Now; GraveyardSaveData graveyardSave = new GraveyardSaveData(save.levelData, save.playerData, currentTime); //Create new file on graveyard path with current timestamp string graveyardPath = Application.persistentDataPath + "/Graveyard" + "/save-" + currentTime.ToString("dd-MM-yyyy_hh-mm-ss") + ".dat"; FileStream stream = new FileStream(graveyardPath, FileMode.Create); //Serialize data into graveyard save formatter.Serialize(stream, graveyardSave); stream.Close(); //Delete save File.Delete(savePath); } else { Debug.Log("No save data present"); } }
public void UpdateSave(GraveyardSaveData save) { Text[] textItems = transform.GetComponentsInChildren <Text>(); deathDate = textItems[0]; survivalTime = textItems[1]; graveyardSave = save; deathDate.text = "" + save.finalDeathTime; survivalTime.text = GetLevel(); }
public void UpdateRecapMenu(GraveyardSaveData saveData) { //Clear skills SkillInventory.instance.skills[0] = null; SkillInventory.instance.skills[1] = null; SkillInventory.instance.skills[2] = null; //Clear pause slots foreach (PauseSkillSlot pauseSlot in pauseSkillScriptList) { pauseSlot.skill = null; } //Loop through saved skill id's foreach (int playerSkill in saveData.playerData.skills) { //Loop through all skills foreach (Skill skill in SkillInventory.instance.allSkills) { //Check if saved skill id matches a skill in all skills list if (playerSkill == skill.skillID) { //If so, add to players current skills SkillInventory.instance.Add(skill); } } } //Enable or disable ui element if no skill in slot foreach (PauseSkillSlot pauseSlot in pauseSkillScriptList) { //if not skill attached, disable if (pauseSlot.skill == null) { pauseSlot.gameObject.SetActive(false); } else if (pauseSlot.skill != null && pauseSlot.gameObject.activeSelf == false) { pauseSlot.gameObject.SetActive(true); } } //Clear items ItemInventory.instance.ClearAllItems(); //Set player items foreach (int playerItem in saveData.playerData.items) { foreach (Item item in ItemInventory.instance.allItems) { if (playerItem == item.itemID) { ItemInventory.instance.items.Add(item); } } } InventoryUI.instance.UpdateInventory(); //Set text elements levelNum.text = "Level: " + saveData.levelData.levelNumber; enemiesSlain.text = "Enemies Slain: " + saveData.levelData.enemiesSlain; //Calculate and show time int seconds = Convert.ToInt32(saveData.levelData.timeSurvived % 60); TimeSpan timePlayedFormatted = TimeSpan.FromSeconds(seconds); timeSurvived.text = "Time: " + string.Format("{0:D2}:{1:D2}:{2:D2}", timePlayedFormatted.Hours, timePlayedFormatted.Minutes, timePlayedFormatted.Seconds); }