Skip to content

Instantly share code, notes, and snippets.

@haim96
Forked from anonymous/PlayerPrefsTools.cs
Created March 13, 2018 13:57
Show Gist options
  • Save haim96/991f73afb0a41a1100e9b9502893f348 to your computer and use it in GitHub Desktop.
Save haim96/991f73afb0a41a1100e9b9502893f348 to your computer and use it in GitHub Desktop.
Get all player prefs keys (windows only)
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