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>)Plist.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>)Plist.readPlist(fi.FullName); keys = new string[plist.Count]; plist.Keys.CopyTo(keys, 0); } return(keys); }