// Start is called before the first frame update void Start() { heroData.Setup(); heroData.ReadData(); // Set up save buttons for (int i = 0; i < NUMBER_OF_SAVESLOTS; i++) { GameObject slotButton = GameObject.Find($"SaveSlot{i + 1}Button"); ActiveSaveSlot slot = (ActiveSaveSlot)i; SaveData data = SaveSystem.LoadFull(slot); if (data == null) // if null then the save file does not exist for this slot { slotButton.GetComponentInChildren <Text>().text = "Empty"; slotButton.GetComponent <Button>().interactable = false; } else { slotButton.GetComponentInChildren <Text>().text = $"{data.HeroInfoData.PlayerName} - {data.Date}"; slotButton.GetComponent <Button>().interactable = true; } } //GameObject slot1Button = GameObject.Find("SaveSlot1Button"); //GameObject slot2Button = GameObject.Find("SaveSlot2Button"); //GameObject slot3Button = GameObject.Find("SaveSlot3Button"); }
public static SaveData LoadFull(ActiveSaveSlot saveSlot = ActiveSaveSlot.Default) { if (saveSlot == ActiveSaveSlot.Default) { saveSlot = activeSaveSlot; } if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } string path = savePath + $"{saveSlot.ToString()}Save.slot"; if (!File.Exists(path)) { Debug.LogWarning($"Save file not found: {path}"); return(null); } BinaryFormatter formatter = GetBinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); try { SaveData data = formatter.Deserialize(stream) as SaveData; stream.Close(); return(data); } catch { stream.Close(); File.Delete(path); Debug.LogWarning($"Loading file at: {path} failed, file has been deleted."); return(null); } }
public static void SetActiveSaveSlot(ActiveSaveSlot slot) { activeSaveSlot = slot; }