private void OnImport() { string importPath = EditorUtility.OpenFilePanel("Import PlayerPrefs", "", "ppe"); if (!string.IsNullOrEmpty(importPath)) { FileInfo fi = new FileInfo(importPath); Dictionary <string, object> plist = (Dictionary <string, object>)Prefslist.readPlist(fi.FullName); foreach (KeyValuePair <string, object> kvp in plist) { PlayerPrefsEntry entry = null; if (kvp.Value is float) { entry = new PlayerPrefsEntry(kvp.Key, (float)kvp.Value); } else if (kvp.Value is int) { entry = new PlayerPrefsEntry(kvp.Key, (int)kvp.Value); } else if (kvp.Value is string) { entry = new PlayerPrefsEntry(kvp.Key, (string)kvp.Value); } if (entry != null) { PlayerPrefsEntry existingEntry = ppeList.Find(p => p.Key == entry.Key); if (existingEntry == null) { ppeList.Add(entry); entry.SaveChanges(); } else if (!entry.Value.Equals(existingEntry.Value) && EditorUtility.DisplayDialog("Duplicate entry found", string.Format("Key \"{0}\" with value \"{1}\" already exists.{2}Do you want to overwrite it with value \"{3}\" ?", existingEntry.Key, existingEntry.Value, Environment.NewLine, entry.Value), "Yes", "No")) { ppeList.Remove(existingEntry); ppeList.Add(entry); entry.SaveChanges(); } } } Sort(); Repaint(); } }
/// <summary> /// On Mac OS X PlayerPrefs are stored in ~/Library/Preferences folder, in a file named unity.[company name].[product name].plist, where company and product names are the names set up in Project Settings. The same .plist file is used for both Projects run in the Editor and standalone players. /// </summary> private string[] GetAllMacKeys() { string plistPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/Library/Preferences/unity." + PlayerSettings.companyName + "." + PlayerSettings.productName + ".plist"; string[] keys = new string[0]; if (File.Exists(plistPath)) { FileInfo fi = new FileInfo(plistPath); Dictionary <string, object> plist = (Dictionary <string, object>)Prefslist.readPlist(fi.FullName); keys = new string[plist.Count]; plist.Keys.CopyTo(keys, 0); } return(keys); }
private void Export(bool onlySelected) { Dictionary <string, object> entries = new Dictionary <string, object>(); for (int i = 0; i < filteredPpeList.Count; i++) { PlayerPrefsEntry entry = filteredPpeList[i]; if (!entries.ContainsKey(entry.Key)) { if (onlySelected == false) { entries.Add(entry.Key, entry.Value); } else if (entry.IsSelected) { entries.Add(entry.Key, entry.Value); } } } if (onlySelected && entries.Count == 0) { Debug.LogError("Cannot export selected entries as no entries has been selected."); } else { string exportPath = EditorUtility.SaveFilePanel("Export all PlayPrefs entries", Application.dataPath, PlayerSettings.productName + "_PlayerPrefs", "ppe"); if (!string.IsNullOrEmpty(exportPath)) { string xml = Prefslist.writeXml(entries); File.WriteAllText(exportPath, xml); AssetDatabase.Refresh(); } } }