/* * Copyright (c) Meta Platforms, Inc. and affiliates. * All rights reserved. * * Licensed under the Oculus SDK License Agreement (the "License"); * you may not use the Oculus SDK except in compliance with the License, * which is provided at the time of installation or download, or which * otherwise accompanies this software in either electronic or hard copy form. * * You may obtain a copy of the License at * * https://developer.oculus.com/licenses/oculussdk/ * * Unless required by applicable law or agreed to in writing, the Oculus SDK * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using UnityEngine; /// /// Represents an XrSpace in the Oculus Runtime. /// /// /// A "space" is an instance of an [XrSpace](https://registry.khronos.org/OpenXR/specs/1.1/html/xrspec.html#XrSpace) in /// the OpenXR runtime and is used typically as the low-level handle of an anchor. /// /// \deprecated Most APIs that use are deprecated. For low-level access to anchors, use /// instead. /// /// Read more about anchors generally at /// [Spatial Anchor Overview](https://developer.oculus.com/documentation/unity/unity-spatial-anchors-persist-content/#ovrspatialanchor-component) /// and /// [Scene Overview](https://developer.oculus.com/documentation/unity/unity-scene-overview/). /// public readonly struct OVRSpace : IEquatable { /// /// \deprecated Represents a storage location for an anchor. /// /// /// \deprecated APIs that accept a storage location are obsolete. /// /// When you save (, /// erase (, /// or load ( a spatial /// anchor using these obsolete APIs, you may specify a storage location to indicate from where you would like to /// save, erase, or load the anchor(s), respectively. /// [Obsolete("Anchor APIs no longer require a storage location.")] public enum StorageLocation { /// /// The storage location is local to the device. /// Local, /// /// The storage location is in the cloud. /// Cloud, } /// /// A runtime handle associated with this . /// /// /// The handle can change between subsequent sessions. To refer to a persistent anchor, use /// to get a unique identifier for the anchor. /// public ulong Handle { get; } /// /// Retrieve the universally unique identifier (UUID) associated with this . /// /// /// Every space that can be persisted will have a UUID associated with it. UUIDs are consistent across different /// sessions and apps. /// /// The UUID of a space does not change over time, but not all spaces are guaranteed to have a UUID. /// /// If successful, the uuid associated with this , otherwise, `Guid.Empty`. /// /// Returns `true` if the uuid could be retrieved, otherwise `false`. public bool TryGetUuid(out Guid uuid) => OVRPlugin.GetSpaceUuid(Handle, out uuid); /// /// Indicates whether this represents a valid space (vs a default constructed /// ). /// public bool Valid => Handle != 0; /// /// Constructs an object from an existing runtime handle and UUID. /// /// /// This constructor does not create a new space. An is a wrapper for low-level functionality /// in the Oculus Runtime. To create a new spatial anchor, use . /// /// The runtime handle associated with the space. public OVRSpace(ulong handle) => Handle = handle; /// /// Generates a string representation of this of the form "0xYYYYYYYY" where "Y" are the /// hexadecimal digits of the . /// /// Returns a string representation of this . public override string ToString() => $"0x{Handle:x16}"; /// /// Compares for equality with another space. /// /// The to compare for equality with this space. /// Returns `true` if the two spaces represent the same space instance, otherwise `false`. public bool Equals(OVRSpace other) => Handle == other.Handle; /// /// Compares for equality with an `object`. /// /// The `object` to compare for equality with this space. /// Returns `true` if is an and represents the same /// space instance as this one, otherwise `false`. public override bool Equals(object obj) => obj is OVRSpace other && Equals(other); /// /// Generates a hash code suitable for use in a `Dictionary` or `HashSet` /// /// Returns a hash code suitable for use in a `Dictionary` or `HashSet` public override int GetHashCode() => Handle.GetHashCode(); /// /// Compares two spaces for equality. /// /// /// This is the same equality test as . /// /// The space to compare with . /// The space to compare with . /// Returns `true` if is equal to , otherwise `false`. public static bool operator ==(OVRSpace lhs, OVRSpace rhs) => lhs.Handle == rhs.Handle; /// /// Compares two spaces for inequality. /// /// /// This is the logical negation of . /// /// The space to compare with . /// The space to compare with . /// Returns `true` if is not equal to , otherwise `false`. public static bool operator !=(OVRSpace lhs, OVRSpace rhs) => lhs.Handle != rhs.Handle; /// /// Casts a `ulong` handle to an . /// /// The handle of the `XrSpace` to convert. /// Returns the as an . public static implicit operator OVRSpace(ulong handle) => new OVRSpace(handle); /// /// Casts an to its underlying `XrSpace` handle. /// /// The to cast. /// Returns the `XrSpace` handle of the . public static implicit operator ulong(OVRSpace space) => space.Handle; } public static partial class OVRExtensions { [Obsolete("Anchor APIs that specify a storage location are obsolete.")] internal static OVRPlugin.SpaceStorageLocation ToSpaceStorageLocation(this OVRSpace.StorageLocation storageLocation) { switch (storageLocation) { case OVRSpace.StorageLocation.Local: return OVRPlugin.SpaceStorageLocation.Local; case OVRSpace.StorageLocation.Cloud: return OVRPlugin.SpaceStorageLocation.Cloud; default: throw new NotSupportedException( $"{storageLocation} is not a supported {nameof(OVRPlugin.SpaceStorageLocation)}"); } } }