using System;
using System.Runtime.InteropServices;
namespace UnityEngine.XR.ARSubsystems
{
///
/// Information about a configuration supported by a .
/// Used by a to select a configuration for the session.
///
///
/// A session provider may have multiple, discrete "modes" of operation each with a different set of capabilities.
/// A configuration descriptor represents the capabilities of a single "mode" of operation,
/// which may be a subset of the session's overal capabilities.
/// That is, the session may support many features, but not all at the same time.
///
///
///
///
[StructLayout(LayoutKind.Sequential)]
public struct ConfigurationDescriptor : IEquatable
{
IntPtr m_Identifier;
Feature m_Capabilities;
int m_Rank;
///
/// A unique identifier for this descriptor.
///
public IntPtr identifier => m_Identifier;
///
/// The capabilities of this configuration.
///
public Feature capabilities => m_Capabilities;
///
/// The "rank" of this configuration relative to other configurations.
/// This can be used by a when deciding
/// between multiple configurations that support the requested s.
///
public int rank => m_Rank;
///
/// Constructs a .
///
/// A unique identifier for this descriptor.
/// The supported capabilities of the configuration.
/// Higher values indicate this configuration should be chosen over another, otherwise equivalent configuration.
public ConfigurationDescriptor(IntPtr identifier, Feature capabilities, int rank)
{
m_Identifier = identifier;
m_Capabilities = capabilities;
m_Rank = rank;
}
unsafe string HexString(IntPtr ptr) => sizeof(IntPtr) == 4 ? $"0x{ptr.ToInt32():x}" : $"0x{ptr.ToInt64():x}";
///
/// Generates a string representation suitable for debugging.
///
/// A string representation suitable for debugging.
public override string ToString() => $"(Identifier: {HexString(identifier)}, Rank: {rank}, Capabilities: {capabilities.ToStringList()})";
///
/// Generates a hash code suitable for use in a Dictionary or HashSet.
///
/// A hash code of this .
public override int GetHashCode() => HashCodeUtil.Combine(m_Identifier.GetHashCode(), ((ulong)m_Capabilities).GetHashCode(), m_Rank.GetHashCode());
///
/// Compares for equality.
///
/// The other to compare against.
/// true if the other is equal to this one.
public bool Equals(ConfigurationDescriptor other) =>
(m_Identifier == other.m_Identifier) &&
(m_Capabilities == other.m_Capabilities) &&
(m_Rank == other.m_Rank);
///
/// Compares for equality.
///
/// The object to compare against.
/// true if is of type and is true.
public override bool Equals(object obj) => (obj is ConfigurationDescriptor) && Equals((ConfigurationDescriptor)obj);
///
/// Compares for equality.
///
/// The left-hand side of the comparison.
/// The right-hand side of the comparison.
/// The same as .
public static bool operator==(ConfigurationDescriptor lhs, ConfigurationDescriptor rhs) => lhs.Equals(rhs);
///
/// Compares for inequality.
///
/// The left-hand side of the comparison.
/// The right-hand side of the comparison.
/// The negation of .
public static bool operator!=(ConfigurationDescriptor lhs, ConfigurationDescriptor rhs) => !lhs.Equals(rhs);
}
}