SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
4.1 KiB

4 years ago
  1. using System;
  2. namespace UnityEngine.XR.ARSubsystems
  3. {
  4. /// <summary>
  5. /// A <c>Guid</c> that can be serialized by Unity. The 128-bit <c>Guid</c>
  6. /// is stored as two 64-bit <c>ulong</c>s. See also the creation utility at
  7. /// <c>UnityEditor.XR.ARSubsystems.SerializableGuidUtil</c>.
  8. /// </summary>
  9. [Serializable]
  10. public struct SerializableGuid : IEquatable<SerializableGuid>
  11. {
  12. /// <summary>
  13. /// Constructs a <see cref="SerializableGuid"/> from two 64-bit <c>ulong</c>s.
  14. /// </summary>
  15. /// <param name="guidLow">The low 8 bytes of the <c>Guid</c>.</param>
  16. /// <param name="guidHigh">The high 8 bytes of the <c>Guid</c>.</param>
  17. public SerializableGuid(ulong guidLow, ulong guidHigh)
  18. {
  19. m_GuidLow = guidLow;
  20. m_GuidHigh = guidHigh;
  21. }
  22. static readonly SerializableGuid k_Empty = new SerializableGuid(0, 0);
  23. /// <summary>
  24. /// Used to represent <c>System.Guid.Empty</c>, e.g., a GUID whose value is all zeros.
  25. /// </summary>
  26. public static SerializableGuid empty => k_Empty;
  27. /// <summary>
  28. /// Reconstructs the <c>Guid</c> from the serialized data.
  29. /// </summary>
  30. public Guid guid => GuidUtil.Compose(m_GuidLow, m_GuidHigh);
  31. public override int GetHashCode()
  32. {
  33. unchecked
  34. {
  35. var hash = m_GuidLow.GetHashCode();
  36. return hash * 486187739 + m_GuidHigh.GetHashCode();
  37. }
  38. }
  39. public override bool Equals(object obj)
  40. {
  41. if (!(obj is SerializableGuid))
  42. return false;
  43. return Equals((SerializableGuid)obj);
  44. }
  45. /// <summary>
  46. /// Generates a string representation of the <c>Guid</c>. Same as <see cref="guid"/><c>.ToString()</c>.
  47. /// See <a href="https://docs.microsoft.com/en-us/dotnet/api/system.guid.tostring?view=netframework-4.7.2#System_Guid_ToString">Microsoft's documentation</a>
  48. /// for more details.
  49. /// </summary>
  50. /// <returns>A string representation of the <c>Guid</c>.</returns>
  51. public override string ToString() => guid.ToString();
  52. /// <summary>
  53. /// Generates a string representation of the <c>Guid</c>. Same as <see cref="guid"/><c>.ToString(format)</c>.
  54. /// </summary>
  55. /// <param name="format">A single format specifier that indicates how to format the value of the <c>Guid</c>.
  56. /// See <a href="https://docs.microsoft.com/en-us/dotnet/api/system.guid.tostring?view=netframework-4.7.2#System_Guid_ToString_System_String_">Microsoft's documentation</a>
  57. /// for more details.</param>
  58. /// <returns>A string representation of the <c>Guid</c>.</returns>
  59. public string ToString(string format) => guid.ToString(format);
  60. /// <summary>
  61. /// Generates a string representation of the <c>Guid</c>. Same as <see cref="guid"/><c>.ToString(format, provider)</c>.
  62. /// </summary>
  63. /// <param name="format">A single format specifier that indicates how to format the value of the <c>Guid</c>.
  64. /// See <a href="https://docs.microsoft.com/en-us/dotnet/api/system.guid.tostring?view=netframework-4.7.2#System_Guid_ToString_System_String_System_IFormatProvider_">Microsoft's documentation</a>
  65. /// for more details.</param>
  66. /// <param name="provider">An object that supplies culture-specific formatting information.</param>
  67. /// <returns>A string representation of the <c>Guid</c>.</returns>
  68. public string ToString(string format, IFormatProvider provider) => guid.ToString(format, provider);
  69. public bool Equals(SerializableGuid other)
  70. {
  71. return
  72. (m_GuidLow == other.m_GuidLow) &&
  73. (m_GuidHigh == other.m_GuidHigh);
  74. }
  75. public static bool operator ==(SerializableGuid lhs, SerializableGuid rhs) => lhs.Equals(rhs);
  76. public static bool operator !=(SerializableGuid lhs, SerializableGuid rhs) => !lhs.Equals(rhs);
  77. [SerializeField]
  78. ulong m_GuidLow;
  79. [SerializeField]
  80. ulong m_GuidHigh;
  81. }
  82. }