private void InstanceSavePanels() { int NumSaveGameLabels; int NumSaveGames; int NumSaveLabelsPerPage = 4; int NumSavePages; string[] SaveGameFileList = SaveManager.GetSaveGameFileList(); int FileCursorIndex; int SaveGameLabelSpawned; NumSaveGames = SaveGameFileList.Length; //If we are in save mode we need NumSaveGames + a new one for saving it. NumSaveGameLabels = IsSaveMode ? NumSaveGames + 1 : NumSaveGames; NumSavePages = (NumSaveGameLabels + NumSaveLabelsPerPage - 1) / NumSaveLabelsPerPage; FileCursorIndex = 0; CurrentPage = 0; SavePanels = new List <GameObject>(); SaveGameLabelSpawned = NumSaveGameLabels; Debug.Log("IsSaveMode: " + IsSaveMode + " NumSaveGames: " + NumSaveGames); Debug.Log("Required labels: " + NumSaveGameLabels); Debug.Log("Required pages: " + NumSavePages); //Spawn the necessary panels... for (int i = 0; i < NumSavePages; i++) { GameObject Parent = Instantiate(Resources.Load("Prefabs/SaveGamePage")) as GameObject; Parent.name = "SavePage" + i; if (i != CurrentPage) { Parent.SetActive(false); } Parent.transform.SetParent(ContentSavePanel.transform, false); SavePanels.Add(Parent); for (int ChildIndex = 0; ChildIndex < NumSaveLabelsPerPage; ChildIndex++) { //We're done. if (SaveGameLabelSpawned <= 0) { break; } GameObject Child = Instantiate(Resources.Load("Prefabs/SaveGameInputField")) as GameObject; Child.name = "SaveLabel" + ChildIndex; InputField ChildInputField = Child.GetComponent <InputField>(); string InText; Debug.Log("FileCursorIndex: " + FileCursorIndex); if (FileCursorIndex < NumSaveGames) { InText = SaveGameFileList[FileCursorIndex]; //Remove the extension. InText = InText.Substring(0, SaveGameFileList[FileCursorIndex].LastIndexOf(".")); } else { InText = ""; } ChildInputField.text = InText; //If we are in load mode we cannot edit on the input... //If we are in save mode and the input represents a saved //game we can only overwrite it. if (!IsSaveMode) { RegisterInputFieldClickEvent(Child, InText); ChildInputField.readOnly = true; } else { if (InText.Length == 0) { ChildInputField.onEndEdit.AddListener(delegate { OnInputFieldValueSubmit(ChildInputField); }); } else { RegisterInputFieldClickEvent(Child, InText, (delegate { OnOverWriteSaveGame(InText); })); ChildInputField.readOnly = true; } } Child.transform.SetParent(Parent.transform, false); FileCursorIndex++; SaveGameLabelSpawned--; } } //Insert order in list may or may be not respected //to be sure we sort them. SavePanels = SavePanels.OrderBy(Panel => Panel.name).ToList(); foreach (GameObject Panel in SavePanels) { Debug.Log("Panel: " + Panel.name); } Debug.Log("NumSaveGamePanel Spawned: " + SavePanels.Count()); }