using System; namespace UnityEngine.XR.ARSubsystems { /// /// A Guid that can be serialized by Unity. The 128-bit Guid /// is stored as two 64-bit ulongs. See also the creation utility at /// UnityEditor.XR.ARSubsystems.SerializableGuidUtil. /// [Serializable] public struct SerializableGuid : IEquatable { /// /// Constructs a from two 64-bit ulongs. /// /// The low 8 bytes of the Guid. /// The high 8 bytes of the Guid. public SerializableGuid(ulong guidLow, ulong guidHigh) { m_GuidLow = guidLow; m_GuidHigh = guidHigh; } static readonly SerializableGuid k_Empty = new SerializableGuid(0, 0); /// /// Used to represent System.Guid.Empty, e.g., a GUID whose value is all zeros. /// public static SerializableGuid empty => k_Empty; /// /// Reconstructs the Guid from the serialized data. /// public Guid guid => GuidUtil.Compose(m_GuidLow, m_GuidHigh); public override int GetHashCode() { unchecked { var hash = m_GuidLow.GetHashCode(); return hash * 486187739 + m_GuidHigh.GetHashCode(); } } public override bool Equals(object obj) { if (!(obj is SerializableGuid)) return false; return Equals((SerializableGuid)obj); } /// /// Generates a string representation of the Guid. Same as .ToString(). /// See Microsoft's documentation /// for more details. /// /// A string representation of the Guid. public override string ToString() => guid.ToString(); /// /// Generates a string representation of the Guid. Same as .ToString(format). /// /// A single format specifier that indicates how to format the value of the Guid. /// See Microsoft's documentation /// for more details. /// A string representation of the Guid. public string ToString(string format) => guid.ToString(format); /// /// Generates a string representation of the Guid. Same as .ToString(format, provider). /// /// A single format specifier that indicates how to format the value of the Guid. /// See Microsoft's documentation /// for more details. /// An object that supplies culture-specific formatting information. /// A string representation of the Guid. public string ToString(string format, IFormatProvider provider) => guid.ToString(format, provider); public bool Equals(SerializableGuid other) { return (m_GuidLow == other.m_GuidLow) && (m_GuidHigh == other.m_GuidHigh); } public static bool operator ==(SerializableGuid lhs, SerializableGuid rhs) => lhs.Equals(rhs); public static bool operator !=(SerializableGuid lhs, SerializableGuid rhs) => !lhs.Equals(rhs); [SerializeField] ulong m_GuidLow; [SerializeField] ulong m_GuidHigh; } }