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 (that is, a GUID whose values are all zeros). /// public static SerializableGuid empty => k_Empty; /// /// Reconstructs the Guid from the serialized data. /// public Guid guid => GuidUtil.Compose(m_GuidLow, m_GuidHigh); /// /// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`. /// /// A hash code generated from this object's fields. public override int GetHashCode() => HashCodeUtil.Combine(m_GuidLow.GetHashCode(), m_GuidHigh.GetHashCode()); /// /// Tests for equality. /// /// The `object` to compare against. /// `True` if is of type and /// also returns `true`; otherwise `false`. public override bool Equals(object obj) => (obj is SerializableGuid) && 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); /// /// Tests for equality. /// /// The other to compare against. /// `True` if every field in is equal to this , otherwise false. public bool Equals(SerializableGuid other) { return (m_GuidLow == other.m_GuidLow) && (m_GuidHigh == other.m_GuidHigh); } /// /// Tests for equality. Same as . /// /// The left-hand side of the comparison. /// The right-hand side of the comparison. /// `True` if is equal to , otherwise `false`. public static bool operator ==(SerializableGuid lhs, SerializableGuid rhs) => lhs.Equals(rhs); /// /// Tests for inequality. Same as `!`. /// /// The left-hand side of the comparison. /// The right-hand side of the comparison. /// `True` if is not equal to , otherwise `false`. public static bool operator !=(SerializableGuid lhs, SerializableGuid rhs) => !lhs.Equals(rhs); [SerializeField] ulong m_GuidLow; [SerializeField] ulong m_GuidHigh; } }