-
-
Save haim96/991f73afb0a41a1100e9b9502893f348 to your computer and use it in GitHub Desktop.
Get all player prefs keys (windows only)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
public class PlayerPrefsTools | |
{ | |
public static void GetAllPlayerPrefKeys(ref List<string> keys) | |
{ | |
if (keys != null) | |
{ | |
keys.Clear(); | |
} | |
else | |
{ | |
keys = new List<string>(); | |
} | |
#if UNITY_STANDALONE_WIN | |
// Unity stores prefs in the registry on Windows | |
string regKeyPathPattern = | |
#if UNITY_EDITOR | |
@"Software\Unity\UnityEditor\{0}\{1}"; | |
#else | |
@"Software\{0}\{1}"; | |
#endif | |
; | |
string regKeyPath = string.Format(regKeyPathPattern, UnityEditor.PlayerSettings.companyName, UnityEditor.PlayerSettings.productName); | |
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(regKeyPath); | |
if (regKey == null) | |
{ | |
return; | |
} | |
string[] playerPrefKeys = regKey.GetValueNames(); | |
for (int i = 0; i < playerPrefKeys.Length; i++) | |
{ | |
string playerPrefKey = playerPrefKeys[i]; | |
// Remove the _hXXXXX suffix | |
playerPrefKey = playerPrefKey.Substring(0, playerPrefKey.LastIndexOf("_h")); | |
keys.Add(playerPrefKey); | |
} | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment