#if !AR_FOUNDATION_PRESENT && !PACKAGE_DOCS_GENERATION // Stub class definition used to fool version defines that this MonoScript exists (fixed in 19.3) namespace UnityEngine.XR.Interaction.Toolkit.AR { /// /// Controls displaying one or more annotations when hovering over the this component is attached to. /// public class ARAnnotationInteractable { } } #else using System; using System.Collections.Generic; namespace UnityEngine.XR.Interaction.Toolkit.AR { /// /// An annotation that appears when the user hovers over the /// that the component governing this annotation is attached to. /// [Serializable] [Obsolete("ARAnnotation has been deprecated. Instead, it is suggested to use LazyFollow and the Hover and Select events from the current interaction system to set the visibility of UGUI canvas objects.")] public class ARAnnotation { #pragma warning disable 618 [SerializeField] [Tooltip("The visualization GameObject that will become active when the object is hovered over.")] GameObject m_AnnotationVisualization; /// /// The visualization that will become active when the user hovers over this object. /// public GameObject annotationVisualization { get => m_AnnotationVisualization; set => m_AnnotationVisualization = value; } [SerializeField] [Tooltip("Maximum angle (in radians) off of FOV horizontal center to show annotation.")] float m_MaxFOVCenterOffsetAngle = 0.25f; /// /// Maximum angle (in radians) off of FOV horizontal center to show annotation. /// public float maxFOVCenterOffsetAngle { get => m_MaxFOVCenterOffsetAngle; set => m_MaxFOVCenterOffsetAngle = value; } [SerializeField] [Tooltip("Minimum range to show annotation at.")] float m_MinAnnotationRange; /// /// Minimum range to show annotation at. /// public float minAnnotationRange { get => m_MinAnnotationRange; set => m_MinAnnotationRange = value; } [SerializeField] [Tooltip("Maximum range to show annotation at.")] float m_MaxAnnotationRange = 10f; /// /// Maximum range to show annotation at. /// public float maxAnnotationRange { get => m_MaxAnnotationRange; set => m_MaxAnnotationRange = value; } #pragma warning restore 618 } /// 5 /// Controls displaying one or more annotations when hovering over the this component is attached to. /// [AddComponentMenu("XR/AR Annotation Interactable", 22)] [HelpURL(XRHelpURLConstants.k_ARAnnotationInteractable)] [Obsolete("ARAnnotationInteractable has been deprecated. Instead, it is suggested to use LazyFollow and the Hover and Select events from the current interaction system to set the visibility of UGUI canvas objects.")] public class ARAnnotationInteractable : ARBaseGestureInteractable { #pragma warning disable 618 [SerializeField] List m_Annotations = new List(); /// /// The list of annotations. /// public List annotations { get => m_Annotations; set => m_Annotations = value; } /// public override void ProcessInteractable(XRInteractionUpdateOrder.UpdatePhase updatePhase) { base.ProcessInteractable(updatePhase); if (updatePhase == XRInteractionUpdateOrder.UpdatePhase.Dynamic) UpdateVisualizations(); } void UpdateVisualizations() { // Disable all annotations if not hovered. if (!isHovered) { foreach (var annotation in m_Annotations) { annotation.annotationVisualization.SetActive(false); } } else { // ReSharper disable once LocalVariableHidesMember -- hide deprecated camera property var camera = xrOrigin != null ? xrOrigin.Camera #pragma warning disable 618 // Calling deprecated property to help with backwards compatibility. : (arSessionOrigin != null ? arSessionOrigin.camera : Camera.main); #pragma warning restore 618 if (camera == null) return; var cameraTransform = camera.transform; var fromCamera = transform.position - cameraTransform.position; var distSquare = fromCamera.sqrMagnitude; fromCamera.y = 0f; fromCamera.Normalize(); var dotProd = Vector3.Dot(fromCamera, cameraTransform.forward); foreach (var annotation in m_Annotations) { var enableThisFrame = (Mathf.Acos(dotProd) < annotation.maxFOVCenterOffsetAngle && distSquare >= Mathf.Pow(annotation.minAnnotationRange, 2f) && distSquare < Mathf.Pow(annotation.maxAnnotationRange, 2f)); if (annotation.annotationVisualization != null) { if (enableThisFrame && !annotation.annotationVisualization.activeSelf) annotation.annotationVisualization.SetActive(true); else if (!enableThisFrame && annotation.annotationVisualization.activeSelf) annotation.annotationVisualization.SetActive(false); // If enabled, align to camera if (annotation.annotationVisualization.activeSelf) { annotation.annotationVisualization.transform.rotation = Quaternion.LookRotation(fromCamera, transform.up); } } } } } #pragma warning restore 618 } } #endif