public void ReadPanel(SavePanel panel) { selectedSave = panel.saveName; if (panel.open) { return; } BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/Saves/" + panel.saveName, FileMode.Open); panel.difficultyText.gameObject.SetActive(true); panel.moneyText.gameObject.SetActive(true); panel.reputationText.gameObject.SetActive(true); LayoutRebuilder.ForceRebuildLayoutImmediate(panel.GetComponent <RectTransform>()); LayoutRebuilder.ForceRebuildLayoutImmediate(saveList.GetComponent <RectTransform>()); SaveData data = (SaveData)bf.Deserialize(file); file.Close(); panel.nameText.text = "Name: " + panel.saveName; panel.difficultyText.text = "Difficulty: " + (Difficulty)data.settings.difficulty; panel.moneyText.text = "Funds: " + data.playerData.money; panel.reputationText.text = "Reputation: " + data.playerData.reputation; panel.open = true; }
public void ResetList() { foreach (Transform child in saveList.transform) { GameObject.Destroy(child.gameObject); } for (int i = 0; i < saves.Length; i++) { SavePanel savePanel = Instantiate(savePanelPrefab, saveList).GetComponent <SavePanel>(); savePanel.saveName = saves[i]; savePanel.nameText.text = saves[i]; savePanel.GetComponent <Button>().onClick.AddListener(() => ReadPanel(savePanel)); } }