using System; #if UNITY_ANDROID using System.Runtime.InteropServices; #endif namespace UnityEngine.XR.ARCore { /// /// Represents the configuration for an . /// /// /// This is an opaque object that represents a native /// [ArConfig](https://developers.google.com/ar/reference/c/group/ar-config). /// /// /// public struct ArConfig : IEquatable, IDisposable { IntPtr m_Self; ArConfig(IntPtr value) => m_Self = value; /// /// Creates a new session configuration and initializes it to a sensible default configuration. /// /// /// Plane detection and Lighting Estimation are enabled, and blocking update is selected. This configuration is /// guaranteed to be supported on all devices that support ARCore. /// /// When you no longer need the , you should destroy it by calling /// . If you do not dispose it, ARCore will leak memory. /// /// A non-null . public ArConfig(ArSession session) => Create(session, out this); /// /// Creates an from an existing native pointer. The native pointer must point /// to an existing . /// /// A pointer to an existing native . /// Returns an whose underlying native pointer is /// . public static ArConfig FromIntPtr(IntPtr value) => new ArConfig(value); /// /// Represents a null , i.e., one whose underlying native pointer is `null`. /// This property is deprecated. Use instead. /// [Obsolete("Use default instead.")] public static ArConfig Null => default; /// /// (Read Only) Indicates whether this is `null`. /// This property is deprecated. Use the equality operator (`==`) to compare with `null` instead. /// [Obsolete("Compare to null instead.")] public bool IsNull => m_Self == IntPtr.Zero; /// /// Gets the underlying native pointer for this . /// /// Returns the underlying native pointer for this . public IntPtr AsIntPtr() => m_Self; /// /// Casts an to its underlying native pointer. /// /// The to cast. /// Returns the underlying native pointer for public static explicit operator IntPtr(ArConfig config) => config.AsIntPtr(); /// /// Tests for equality. /// /// /// Two s are considered equal if their underlying pointers are equal. /// /// The to compare against. /// Returns `true` if the underlying native pointers are the same. Returns `false` otherwise. public bool Equals(ArConfig other) => m_Self == other.m_Self; /// /// Tests for equality. /// /// An to compare against. /// Returns `true` if is an and it compares /// equal to this one using . public override bool Equals(object obj) => obj is ArConfig other && Equals(other); /// /// Generates a hash code suitable for use with a `HashSet` or `Dictionary` /// /// Returns a hash code for this . public override int GetHashCode() => m_Self.GetHashCode(); /// /// Tests for equality. Same as . /// /// The to compare with . /// The to compare with . /// Returns `true` if is equal to using /// . Returns `false` otherwise. public static bool operator ==(ArConfig lhs, ArConfig rhs) => lhs.Equals(rhs); /// /// Tests for inequality. Same as the negation of . /// /// The to compare with . /// The to compare with . /// Returns `false` if is equal to using /// . Returns `true` otherwise. public static bool operator !=(ArConfig lhs, ArConfig rhs) => !lhs.Equals(rhs); /// /// Destroys this and sets the underlying native pointer to `null`. /// /// /// You should only dispose an if you explicitly created it, e.g., by calling /// . If you convert an existing config from an /// (e.g., by calling ), then you should not dispose it. /// public void Dispose() { if (m_Self != IntPtr.Zero) { Destroy(this); } m_Self = IntPtr.Zero;; } /// /// Tests for equality. /// /// /// This equality operator lets you to compare an with `null` to determine whether its /// underlying pointer is null. This allows for a more natural comparison with the native ARCore object: /// /// /// bool TestForNull(ArConfig obj) /// { /// if (obj == null) /// { /// // obj.AsIntPtr() is IntPtr.Zero /// } /// } /// /// /// /// The nullable to compare with . /// The nullable to compare with . /// Returns true if any of these conditions are met: /// - and are both not null and their underlying pointers are equal. /// - is null and 's underlying pointer is null. /// - is null and 's underlying pointer is null. /// - Both and are null. /// /// Returns false otherwise. /// public static bool operator ==(ArConfig? lhs, ArConfig? rhs) => NativeObject.ArePointersEqual(lhs?.m_Self, rhs?.m_Self); /// /// Tests for inequality. /// /// /// This inequality operator lets you to compare an with `null` to determine whether its /// underlying pointer is null. This allows for a more natural comparison with the native ARCore object: /// /// /// bool TestForNull(ArConfig obj) /// { /// if (obj != null) /// { /// // obj.AsIntPtr() is not IntPtr.Zero /// } /// } /// /// /// /// The native object to compare with . /// The native object to compare with . /// Returns false if any of these conditions are met: /// - and are both not null and their underlying pointers are equal. /// - is null and 's underlying pointer is null. /// - is null and 's underlying pointer is null. /// - Both and are null. /// /// Returns true otherwise. /// public static bool operator !=(ArConfig? lhs, ArConfig? rhs) => !(lhs == rhs); #if UNITY_EDITOR static void Create(ArSession session, out ArConfig configOut) => configOut = default; static void Destroy(ArConfig config) { } #elif UNITY_ANDROID [DllImport("arcore_sdk_c", EntryPoint = "ArConfig_create")] static extern void Create(ArSession session, out ArConfig configOut); [DllImport("arcore_sdk_c", EntryPoint = "ArConfig_destroy")] static extern void Destroy(ArConfig config); #endif } }