private void SetupSaveSlotScreen() { for (int i = 0; i < slotTexts.Length; i++) { int slot = i; // to conserve the slot index in the OnClick attribute. if (SaveLoadManager.CheckSlot(i)) { // Load data of the slot. PlayerProgress progress = SaveLoadManager.LoadPlayerProgress(slot); // Update treasures found. treasuresParent[i].SetActive(progress.treasuresFound.Count > 0); // foreach treasure... display it. // Update slot information. slotTexts[i].text = "Slot " + (slot + 1).ToString() + " - " + 0 + "%"; // TODO load completion percent. moreInformationTexts[i].text = "Time : " + GetTimeFormated(progress.timePlayed); moreInformationTexts[i].gameObject.SetActive(true); } else { treasuresParent[i].SetActive(false); moreInformationTexts[i].gameObject.SetActive(false); // Update slot information. slotTexts[i].text = "Slot " + (slot + 1).ToString() + " - empty"; } } }
// Setup action of the button. private void SetupActionInSlotMenu(bool isNewGame) { if (isNewGame) { slotMenuTitle.text = "Start new game :"; } else { slotMenuTitle.text = "Load a game :"; } for (int i = 0; i < slotButtons.Length; i++) { int slot = i; slotButtons[i].onClick.RemoveAllListeners(); bool slotNotEmpty = SaveLoadManager.CheckSlot(i); if (isNewGame) { // All slot can be used to create new game. slotButtons[i].interactable = true; if (slotNotEmpty) { slotButtons[i].onClick.AddListener(() => GameManager.instance.NewGame(slot, true)); } else { slotButtons[i].onClick.AddListener(() => GameManager.instance.NewGame(slot, false)); } } else { if (slotNotEmpty) { slotButtons[i].interactable = true; slotButtons[i].onClick.AddListener(() => GameManager.instance.LoadPlayerProgress(slot)); } // An empty slot can't be loaded. else { slotButtons[i].interactable = false; } } } }