Skip to content

Instantly share code, notes, and snippets.

@phosphoer
Created December 15, 2021 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phosphoer/053a1d8fb7390846c90d7f82b282b7d9 to your computer and use it in GitHub Desktop.
Save phosphoer/053a1d8fb7390846c90d7f82b282b7d9 to your computer and use it in GitHub Desktop.
Unity PlayerPrefs Registry Hash
public class PlayerPrefsHash
{
// Returns the string property name Unity would generate for a player prefs registry key value
// e.g., "PlayerGold" -> "PlayerGold_hXXXXXXXXXXXXXX"
public static string Hash(string name)
{
uint hash = 5381;
foreach (char c in name)
hash = hash * 33 ^ c;
string key = name + "_h" + hash;
return key;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment