public virtual void Save() { if (SaveAndLoadManager.Instance != this) { SaveAndLoadManager.Instance.Save(); return; } // Setup (); print("Save"); if (!usePlayerPrefs) { savedData = ""; if (!File.Exists(Application.persistentDataPath + Path.DirectorySeparatorChar + "Saved Data.txt")) { File.CreateText(Application.persistentDataPath + Path.DirectorySeparatorChar + "Saved Data.txt"); } else { savedData = File.ReadAllText(Application.persistentDataPath + Path.DirectorySeparatorChar + "Saved Data.txt"); string[] valueGroups = savedData.Split(new string[] { SaveEntry.VALUE_GROUP_SEPERATOR }, StringSplitOptions.None); for (int i = 0; i < valueGroups.Length; i += 2) { string valueGroup = valueGroups[i]; if (valueGroup.StartsWith("" + AccountManager.lastUsedAccountIndex)) { savedData = savedData.RemoveEach(valueGroup + SaveEntry.VALUE_GROUP_SEPERATOR + valueGroups[i + 1] + SaveEntry.VALUE_GROUP_SEPERATOR); } } } } if (AccountManager.lastUsedAccountIndex != -1) { for (int i = 0; i < saveEntries.Length; i++) { SaveEntry saveEntry = saveEntries[i]; if (AccountManager.CurrentlyPlaying.MostRecentlyUsedSaveEntryIndex > pastSaveEntryPreserveCount) { saveEntry.Delete(AccountManager.lastUsedAccountIndex, AccountManager.CurrentlyPlaying.MostRecentlyUsedSaveEntryIndex - pastSaveEntryPreserveCount); } saveEntry.Save(AccountManager.lastUsedAccountIndex, AccountManager.CurrentlyPlaying.MostRecentlyUsedSaveEntryIndex); AccountManager.CurrentlyPlaying.MostRecentlyUsedSaveEntryIndex++; if (AccountManager.CurrentlyPlaying.MostRecentlyUsedSaveEntryIndex > AccountManager.CurrentlyPlaying.LastSaveEntryIndex) { AccountManager.CurrentlyPlaying.LastSaveEntryIndex++; } } } else { for (int i = 0; i < saveEntries.Length; i++) { saveEntries[i].Save(AccountManager.lastUsedAccountIndex, AccountManager.lastUsedAccountIndex); } } if (!usePlayerPrefs) { File.WriteAllText(Application.persistentDataPath + Path.DirectorySeparatorChar + "Saved Data.txt", savedData); } displayOnSave.Do(); }
public virtual void Save(int accountIndex, int saveIndex) { if (SaveAndLoadManager.Instance != this) { SaveAndLoadManager.instance.SaveToCurrentAccount(); return; } OnAboutToSave(); // Setup (); // savedData = ""; if (!usePlayerPrefs) { if (!File.Exists(Application.persistentDataPath + Path.DirectorySeparatorChar + "Saved Data.txt")) { File.CreateText(Application.persistentDataPath + Path.DirectorySeparatorChar + "Saved Data.txt"); } else { savedData = File.ReadAllText(Application.persistentDataPath + Path.DirectorySeparatorChar + "Saved Data.txt"); string[] valueGroups = savedData.Split(new string[] { SaveEntry.VALUE_GROUP_SEPERATOR }, StringSplitOptions.None); for (int i = 0; i < valueGroups.Length; i += 2) { string valueGroup = valueGroups[i]; if (valueGroup.StartsWith("" + accountIndex)) { savedData = savedData.RemoveEach(valueGroup + SaveEntry.VALUE_GROUP_SEPERATOR + valueGroups[i + 1] + SaveEntry.VALUE_GROUP_SEPERATOR); } } } } if (accountIndex != -1) { Account account = ArchivesManager.Accounts[accountIndex]; account.MostRecentlyUsedSaveIndex = saveIndex; if (account.MostRecentlyUsedSaveIndex > ArchivesManager.CurrentlyPlaying.LastSaveIndex) { account.LastSaveIndex++; } for (int i = 0; i < saveEntries.Length; i++) { SaveEntry saveEntry = saveEntries[i]; if (ArchivesManager.CurrentlyPlaying.MostRecentlyUsedSaveIndex > keepPastSavesCount) { saveEntry.Delete(accountIndex, ArchivesManager.CurrentlyPlaying.LastSaveIndex - keepPastSavesCount - 1); } saveEntry.Save(accountIndex, saveIndex); } } else { for (int i = 0; i < saveEntries.Length; i++) { saveEntries[i].Save(-1, -1); } } if (!usePlayerPrefs) { File.WriteAllText(Application.persistentDataPath + Path.DirectorySeparatorChar + "Saved Data.txt", savedData); } displayOnSave.Do(); }