void OnEnable() { SavingWrapper savingWrapper = FindObjectOfType <SavingWrapper>(); if (savingWrapper == null) { return; } foreach (Transform child in contentRoot) { Destroy(child.gameObject); } foreach (string save in savingWrapper.ListSaves()) { GameObject rowInstance = Instantiate(rowPrefab, contentRoot); Button loadButton = rowInstance.GetComponent <LoadButtonSetup>().GetLoadButton(); Button deleteButton = rowInstance.GetComponent <LoadButtonSetup>().GetDeleteButton(); TMP_Text textComp = loadButton.GetComponentInChildren <TMP_Text>(); textComp.text = save; loadButton.onClick.AddListener(() => { savingWrapper.LoadGame(save); }); deleteButton.onClick.AddListener(() => { savingWrapper.DeleteSavedGame(save); Destroy(rowInstance); }); } }
private void OnEnable() { SavingWrapper savingWrapper = FindObjectOfType <SavingWrapper>(); if (savingWrapper == null) { return; } foreach (Transform child in contentRoot) { Destroy(child.gameObject); } foreach (string save in savingWrapper.ListSaves()) { GameObject buttonInstance = Instantiate(buttonPrefab, contentRoot); TMP_Text textComp = buttonInstance.GetComponentInChildren <TMP_Text>(); textComp.text = save; Button button = buttonInstance.GetComponentInChildren <Button>(); button.onClick.AddListener(() => { savingWrapper.LoadGame(save); }); } }