暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SpriteLibraryUtility.cs 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. namespace UnityEngine.U2D.Animation
  3. {
  4. internal static class SpriteLibraryUtility
  5. {
  6. // Allow delegate override for test
  7. internal static Func<string, int> GetStringHash = Bit30Hash_GetStringHash;
  8. /// <summary>
  9. /// Used to convert Sprite Key to the new Sprite Hash.
  10. /// </summary>
  11. /// <param name="input">Sprite Key to convert</param>
  12. /// <returns></returns>
  13. internal static int Convert32BitTo30BitHash(int input)
  14. {
  15. var output = PreserveFirst30Bits(input);
  16. return output;
  17. }
  18. static int Bit30Hash_GetStringHash(string value)
  19. {
  20. #if DEBUG_GETSTRINGHASH_CLASH
  21. if (value == "abc" || value == "123")
  22. value = "abc";
  23. #endif
  24. var hash = Animator.StringToHash(value);
  25. hash = PreserveFirst30Bits(hash);
  26. return hash;
  27. }
  28. static int PreserveFirst30Bits(int input)
  29. {
  30. const int mask = 0x3FFFFFFF;
  31. return input & mask;
  32. }
  33. internal static long GenerateHash()
  34. {
  35. var hash = DateTime.Now.Ticks;
  36. return hash;
  37. }
  38. }
  39. }