Created
December 15, 2021 19:30
-
-
Save phosphoer/053a1d8fb7390846c90d7f82b282b7d9 to your computer and use it in GitHub Desktop.
Unity PlayerPrefs Registry Hash
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
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