InputUserAccountHandle.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. namespace UnityEngine.InputSystem.Users
  3. {
  4. /// <summary>
  5. /// Handle for a user account in an external API.
  6. /// </summary>
  7. public struct InputUserAccountHandle : IEquatable<InputUserAccountHandle>
  8. {
  9. /// <summary>
  10. /// Symbolic name of the API that owns the handle.
  11. /// </summary>
  12. /// <remarks>
  13. /// This essentially provides a namespace for <see cref="handle"/>.
  14. ///
  15. /// On PS4, for example, this will read "PS4" for user handles corresponding
  16. /// to <c>sceUserId</c>.
  17. ///
  18. /// This will not be null or empty except if the handle is invalid.
  19. /// </remarks>
  20. public string apiName
  21. {
  22. get { return m_ApiName; }
  23. }
  24. public ulong handle
  25. {
  26. get { return m_Handle; }
  27. }
  28. public InputUserAccountHandle(string apiName, ulong handle)
  29. {
  30. if (string.IsNullOrEmpty(apiName))
  31. throw new ArgumentNullException("apiName");
  32. m_ApiName = apiName;
  33. m_Handle = handle;
  34. }
  35. public override string ToString()
  36. {
  37. if (m_ApiName == null)
  38. return base.ToString();
  39. return string.Format("{0}({1})", m_ApiName, m_Handle);
  40. }
  41. public bool Equals(InputUserAccountHandle other)
  42. {
  43. return string.Equals(apiName, other.apiName) && Equals(handle, other.handle);
  44. }
  45. public override bool Equals(object obj)
  46. {
  47. if (ReferenceEquals(null, obj))
  48. return false;
  49. return obj is InputUserAccountHandle && Equals((InputUserAccountHandle)obj);
  50. }
  51. public static bool operator==(InputUserAccountHandle left, InputUserAccountHandle right)
  52. {
  53. return left.Equals(right);
  54. }
  55. public static bool operator!=(InputUserAccountHandle left, InputUserAccountHandle right)
  56. {
  57. return !left.Equals(right);
  58. }
  59. public override int GetHashCode()
  60. {
  61. unchecked
  62. {
  63. return ((apiName != null ? apiName.GetHashCode() : 0) * 397) ^ handle.GetHashCode();
  64. }
  65. }
  66. private string m_ApiName;
  67. private ulong m_Handle;
  68. }
  69. }