using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using Unity.XR.CoreUtils.Collections; using UnityEngine.XR.ARSubsystems; namespace UnityEngine.XR.ARFoundation { /// /// A structure for occlusion information pertaining to a particular frame. This is used to communicate information /// in the event. /// public struct AROcclusionFrameEventArgs : IEquatable { /// /// The occlusion textures associated with this frame. These are generally external textures, which exist only /// on the GPU. To use them on the CPU (for example, for computer vision processing), you must read them back /// from the GPU. /// [Obsolete("textures has been deprecated in AR Foundation version 6.1. Use externalTextures instead.")] public List textures { get { var list = new List(); foreach (var tex in externalTextures) { if (tex.texture is Texture2D tex2D) list.Add(tex2D); } return list; } } /// /// Ids of the property name associated with each texture. This is a parallel list to `textures`. /// [Obsolete("propertyNameIds has been deprecated in AR Foundation version 6.1. Use externalTextures instead.")] public List propertyNameIds { get { var list = new List(); foreach (var tex in externalTextures) { if (tex.texture is Texture2D) list.Add(tex.propertyId); } return list; } } /// /// The list of keywords to be enabled for the material. /// [Obsolete("enabledMaterialKeywords has been deprecated in AR Foundation version 6.0. Use shaderKeywords instead.")] public List enabledMaterialKeywords => shaderKeywords.enabledKeywords != null ? new(shaderKeywords.enabledKeywords.ToArray()) : null; /// /// The list of keywords to be disabled for the material. /// [Obsolete("disabledMaterialKeywords has been deprecated in AR Foundation version 6.0. Use shaderKeywords instead.")] public List disabledMaterialKeywords => shaderKeywords.disabledKeywords != null ? new(shaderKeywords.disabledKeywords.ToArray()) : null; /// /// The enabled shader keywords. /// [Obsolete("enabledShaderKeywords is deprecated as of AR Foundation 6.1. Use shaderKeywords instead.")] public ReadOnlyCollection enabledShaderKeywords => shaderKeywords.enabledKeywords != null ? new(shaderKeywords.enabledKeywords.ToArray()) : null; /// /// The disabled shader keywords. /// [Obsolete("disabledShaderKeywords is deprecated as of AR Foundation 6.1. Use shaderKeywords instead")] public ReadOnlyCollection disabledShaderKeywords => shaderKeywords.disabledKeywords != null ? new(shaderKeywords.disabledKeywords.ToArray()) : null; /// /// The enabled and disabled shader keywords. /// public XRShaderKeywords shaderKeywords { get; internal set; } /// /// All external textures associated with occlusion for this frame. /// public ReadOnlyList externalTextures { get; internal set; } internal XROcclusionFrameProperties properties { private get; set; } /// /// The timestamp of the frame, in nanoseconds. /// internal long timestamp { private get; set; } internal XRNearFarPlanes nearFarPlanes { private get; set; } internal ReadOnlyList poses { private get; set; } internal ReadOnlyList fovs { private get; set; } /// /// Get the timestamp of the frame, if possible. /// /// The timestamp of the camera frame, in nanoseconds. /// if the frame has a timestamp that was output to . /// Otherwise, . public bool TryGetTimestamp(out long timestampOut) { if ((properties & XROcclusionFrameProperties.Timestamp) != 0) { timestampOut = timestamp; return true; } timestampOut = default; return false; } /// /// Get the near and far planes for the frame, if possible. /// /// The near and far planes. /// if the frame has near and far planes that were output to . /// Otherwise, . public bool TryGetNearFarPlanes(out XRNearFarPlanes planesOut) { if ((properties & XROcclusionFrameProperties.NearFarPlanes) != 0) { planesOut = nearFarPlanes; return true; } planesOut = default; return false; } /// /// Get an array of poses from which the frame was rendered, if possible. /// Poses are in Unity world space. /// /// The output array of poses, if this method returns . /// if the frame has poses that were output to . /// Otherwise, . public bool TryGetPoses(out ReadOnlyList posesOut) { if ((properties & XROcclusionFrameProperties.Poses) != 0) { posesOut = poses; return true; } posesOut = default; return false; } /// /// Get an array of fields of view for the frame if possible. /// /// The output array of fields of view, if this method returns . /// if the frame has fields of view that were output to . /// Otherwise, . public bool TryGetFovs(out ReadOnlyList fovsOut) { if ((properties & XROcclusionFrameProperties.Fovs) != 0) { fovsOut = fovs; return true; } fovsOut = default; return false; } /// /// Tests for equality. /// /// The object to compare against. /// if is of type and /// also returns . /// Otherwise, . public override bool Equals(object obj) => obj is AROcclusionFrameEventArgs args && Equals(args); /// /// Tests for equality. Equivalent to . /// /// The left-hand side of the comparison. /// The right-hand side of the comparison. /// if is equal to . /// Otherwise, . public static bool operator ==(AROcclusionFrameEventArgs lhs, AROcclusionFrameEventArgs rhs) => lhs.Equals(rhs); /// /// Tests for inequality. Equivalent to `!`. /// /// The left-hand side of the comparison. /// The right-hand side of the comparison. /// if is not equal to . /// Otherwise, . public static bool operator !=(AROcclusionFrameEventArgs lhs, AROcclusionFrameEventArgs rhs) => !lhs.Equals(rhs); /// /// Serves as the default hash function. /// /// A hash code for the current object. public override int GetHashCode() { var hashCode = new HashCode(); hashCode.Add(shaderKeywords); hashCode.Add((int)properties); hashCode.Add(timestamp); hashCode.Add(nearFarPlanes); hashCode.Add(poses); hashCode.Add(fovs); hashCode.Add(externalTextures); return hashCode.ToHashCode(); } /// /// Indicates whether the current object is equal to another object of the same type. Collections are compared /// using reference equality. /// /// An object to compare with this object. /// if the current object is equal to . /// Otherwise, . public bool Equals(AROcclusionFrameEventArgs other) { return Equals(shaderKeywords, other.shaderKeywords) && properties == other.properties && timestamp == other.timestamp && nearFarPlanes.Equals(other.nearFarPlanes) && Equals(poses, other.poses) && Equals(fovs, other.fovs) && Equals(externalTextures, other.externalTextures); } /// /// Returns a string that represents the current object. /// /// The string. public override string ToString() { var sb = new StringBuilder(); sb.AppendLine("{"); sb.AppendLine($" shaderKeywords: {shaderKeywords.ToString()},"); sb.AppendLine($" properties: {properties.ToString()},"); sb.AppendLine($" timestamp: {timestamp.ToString()},"); sb.AppendLine($" nearFarPlanes: {nearFarPlanes.ToString()},"); sb.AppendLine($" poses: {poses},"); sb.AppendLine($" fovs: {fovs},"); sb.AppendLine($" externalTextures: {externalTextures},"); sb.AppendLine("}"); var result = sb.ToString(); sb.Clear(); return result; } } }