FixedStringHelper.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Unity.Collections;
  2. using Unity.Burst;
  3. using Unity.Mathematics;
  4. using Unity.Collections.LowLevel.Unsafe;
  5. namespace LitMotion
  6. {
  7. [BurstCompile]
  8. internal unsafe static partial class FixedStringHelper
  9. {
  10. static readonly char[] LowercaseChars = new char[]
  11. {
  12. 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
  13. };
  14. static readonly char[] UppercaseChars = new char[]
  15. {
  16. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
  17. };
  18. static readonly char[] NumeralsChars = new char[]
  19. {
  20. '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
  21. };
  22. static readonly char[] AllChars = new char[]
  23. {
  24. 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  25. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  26. '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
  27. };
  28. static char GetScrambleChar(ScrambleMode scrambleMode, ref Random random)
  29. {
  30. return scrambleMode switch
  31. {
  32. ScrambleMode.None => default,
  33. ScrambleMode.Uppercase => UppercaseChars[random.NextInt(0, UppercaseChars.Length)],
  34. ScrambleMode.Lowercase => LowercaseChars[random.NextInt(0, LowercaseChars.Length)],
  35. ScrambleMode.Numerals => NumeralsChars[random.NextInt(0, NumeralsChars.Length)],
  36. ScrambleMode.All => AllChars[random.NextInt(0, AllChars.Length)],
  37. _ => default
  38. };
  39. }
  40. }
  41. }