public void Save(Dictionary <string, int> currency) { if (currency != null) { using (MemoryStream ms = new MemoryStream()) { converter.Serialize(currency, ms); ms.Seek(0, SeekOrigin.Begin); using (TextReader tr = new StreamReader(ms, Encoding.UTF8)) { PlayerPrefs.SetString(StorageName, tr.ReadToEnd()); PlayerPrefs.Save(); } } } }
public void Save(Dictionary <string, int> currency) { if (currency != null) { if (File.Exists(FilePath)) { File.Delete(FilePath); } var dirPath = Path.GetDirectoryName(FilePath); if (!string.IsNullOrEmpty(dirPath)) { if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } } using (var fileAccess = File.Open(FilePath, FileMode.Create, FileAccess.Write)) { converter.Serialize(currency, fileAccess); } } }