private void OnEnable() { DirectoryInfo saveDirectory = new DirectoryInfo($@"{Application.persistentDataPath}\saves"); DirectoryInfo[] subDirectories = saveDirectory.GetDirectories(); List <SaveData.Metadata> metadatas = new List <SaveData.Metadata>(); foreach (DirectoryInfo subDir in subDirectories) { string metaFilePath = $@"{subDir.ToString()}\meta.json"; if (File.Exists(metaFilePath)) { try { metadatas.Add(JsonUtility.FromJson <SaveData.Metadata>(File.ReadAllText(metaFilePath))); } catch { } } } SaveData.Metadata[] saveDatas = metadatas.OrderByDescending((m) => m.lastSave).ToArray(); foreach (SaveData.Metadata metadata in saveDatas) { GameObject entry = Instantiate(menuEntryPrefab, content); SaveMenuEntry saveMenuEntry = entry.GetComponent <SaveMenuEntry>(); saveMenuEntry.SetInfo(metadata.saveName, metadata.lastSave); saveMenuEntries.Add(saveMenuEntry); saveMenuEntry.GetComponent <Image>().color = unselectedEntryColor; } loadButton.interactable = deleteButton.interactable = selectedEntry != null; }
private void OnDisable() { SelectedEntry = null; foreach (SaveMenuEntry saveMenuEntry in saveMenuEntries) { Destroy(saveMenuEntry.gameObject); } saveMenuEntries.Clear(); }