private void Export(bool onlySelected) { Dictionary <string, object> entries = new Dictionary <string, object>(); for (int i = 0; i < this.filteredPpeList.Count; i++) { if (onlySelected == false) { entries.Add(this.filteredPpeList[i].Key, this.filteredPpeList[i].Value); } else if (this.filteredPpeList[i].IsSelected) { entries.Add(this.filteredPpeList[i].Key, this.filteredPpeList[i].Value); } } if (onlySelected && entries.Count == 0) { Debug.LogError("Cannot export selected entries as no entries has been selected."); } else { string exportPath = EditorUtility.SaveFilePanelInProject("Export all PlayPrefs entries", PlayerSettings.productName + "_PlayerPrefs", "ppe", "Export all PlayerPrefs entries"); if (!string.IsNullOrEmpty(exportPath)) { string xml = Plist.writeXml(entries); File.WriteAllText(exportPath, xml); AssetDatabase.Refresh(); } } }
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); }
/// <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 companyName = ReplaceSpecialCharacters(PlayerSettings.companyName); string productName = ReplaceSpecialCharacters(PlayerSettings.productName); string plistPath = string.Format("{0}/Library/Preferences/unity.{1}.{2}.plist", Environment.GetFolderPath(Environment.SpecialFolder.Personal), companyName, productName); 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); }
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) { ppeList.Add(entry); entry.SaveChanges(); } } Sort(); Repaint(); } }