Created
March 13, 2018 10:34
-
-
Save GFX47/782b28f5143a38e7b5f441d86d538cec 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; | |
using UnityEngine; | |
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, Application.companyName, Application.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