private void CacheRecord(string key, object value) { // First of all check if this key already exists, if so replace it's value with the new value/ var replaced = false; var entryCount = deserializedPlayerPrefs.Count; for (int i = 0; i < entryCount; i++) { if (deserializedPlayerPrefs[i].Key == key) { deserializedPlayerPrefs[i] = new PrefPair { Key = key, Value = value }; replaced = true; break; } } // PlayerPref doesn't already exist (and wasn't replaced) so add it as new. if (!replaced) { // Cache a PlayerPref the user just created so it can be instantly display (mainly for OSX) deserializedPlayerPrefs.Add(new PrefPair { Key = key, Value = value }); } // Update the search if it's active UpdateSearch(); }
/// <summary> /// This returns an array of the stored PlayerPrefs from the Windows registry, to allow /// us to to look up what's actually in the PlayerPrefs. This is used as a kind of lookup table. /// </summary> private PrefPair[] RetrieveSavedPrefs(string companyName, string productName) { RegistryKey registryKey; if (showEditorPrefs) { var majorVersion = Application.unityVersion.Split('.')[0]; registryKey = Registry.CurrentUser.OpenSubKey("Software\\Unity Technologies\\Unity Editor " + majorVersion + ".x"); } // On Windows, PlayerPrefs are stored in the registry under HKCU\Software\[company name]\[product name] key, where company and product names are the names set up in Project Settings. else { registryKey = Registry.CurrentUser.OpenSubKey("Software\\Unity\\UnityEditor\\" + companyName + "\\" + productName); } // No prefs saved for the project. if (registryKey is null) { return(new PrefPair[0]); } var valueNames = registryKey.GetValueNames(); var tempPlayerPrefs = new PrefPair[valueNames.Length]; for (int i = 0; i < valueNames.Length; i++) { var valueName = valueNames[i]; var key = valueNames[i]; // Remove the _h193410979 style suffix used on PlayerPref keys in Windows registry. var index = key.LastIndexOf("_"); key = key.Remove(index, key.Length - index); var ambiguousValue = registryKey.GetValue(valueName); // Unfortunately floats will come back as an int (at least on 64 bit) because the float is stored as // 64 bit but marked as 32 bit - which confuses the GetValue() method greatly! if (ambiguousValue.GetType() == typeof(int)) { // If the PlayerPref is not actually an int then it must be a float, this will evaluate to true // (impossible for it to be 0 and -1 at the same time). if (GetInt(key, -1) == -1 && GetInt(key, 0) == 0) { ambiguousValue = GetFloat(key); } // If it reports a non default value as a bool, it's a bool not a string. else if (showEditorPrefs && (GetBool(key, true) != true || GetBool(key, false) != false)) { ambiguousValue = GetBool(key); } } else if (ambiguousValue.GetType() == typeof(byte[])) { // On Unity 5 a string may be stored as binary, so convert it back to a string. ambiguousValue = encoding.GetString((byte[])ambiguousValue).TrimEnd('\0'); } tempPlayerPrefs[i] = new PrefPair() { Key = key, Value = ambiguousValue }; } return(tempPlayerPrefs); }