public void GenerateLoadBoardsMenu() { // delete the existing menu, if it exists. The menu needs to be regenerated when something is renamed or deleted foreach (UISavedBoard uisave in UISavedBoards) { Destroy(uisave.gameObject); } UISavedBoards.Clear(); int Saves = LoadBoardsAndReturnTheNumberOfBoards(); // set the content field to the correct length for the number of saves Parent.sizeDelta = new Vector2(784, 20 + Saves * 110); }
public int LoadBoardsAndReturnTheNumberOfBoards() { string BoardsDirectory = Application.persistentDataPath + "/savedboards/"; if (!Directory.Exists(BoardsDirectory)) { Directory.CreateDirectory(BoardsDirectory); } string[] files = Directory.GetFiles(BoardsDirectory); // make sure they're .tungboard files List <string> boardpaths = new List <string>(); foreach (string file in files) { if (file.Substring(file.Length - 10) == ".tungboard") { boardpaths.Add(file); } } for (int i = 0; i < boardpaths.Count; i++) { GameObject penis = Instantiate(SavedBoardPrefab, Parent); FileInfo penisinfo = new FileInfo(boardpaths[i]); UISavedBoard v****a = penis.GetComponent <UISavedBoard>(); v****a.FilePath = boardpaths[i]; v****a.Title.text = Path.GetFileNameWithoutExtension(boardpaths[i]); v****a.SetPosition(i); // new method of setting position v****a.Info.text = penisinfo.Length.ToString() + " bytes" // get file size ; // + " | " + penisinfo.LastAccessTime.ToString(); // get the local time of the last time the save was modified UISavedBoards.Add(v****a); } Debug.Log(boardpaths.Count.ToString() + " saved boards"); return(boardpaths.Count); }