Last active
November 26, 2021 16:12
-
-
Save hybridherbst/90d554dfb6791517acb2d75af6baf516 to your computer and use it in GitHub Desktop.
Unity PlayerPref & EditorPref hash handling
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
// Unity hashes PlayerPref names to make them case-sensitive | |
// (Windows Registry isn't case sensitive otherwise) | |
private static string ToKey(string prefName) | |
{ | |
return prefName + "_h" + Hash(prefName); | |
} | |
// djb2-xor hash method | |
private static uint Hash(string str) | |
{ | |
uint hash = 5381; | |
if (string.IsNullOrEmpty(str)) return hash; | |
foreach (var c in str) | |
hash = hash * 33 ^ c; | |
return hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment