using System; using UnityEngine.XR.ARSubsystems; namespace UnityEngine.XR.ARFoundation { /// /// The base class for all types. /// /// /// A "trackable" is something that is tracked in the physical environment. These include: /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// public abstract class ARTrackable : MonoBehaviour, ITrackable { /// public abstract TrackableId trackableId { get; } /// public abstract Pose pose { get; } /// public abstract TrackingState trackingState { get; } /// public abstract IntPtr nativePtr { get; } } /// /// A generic component for trackables. A "trackable" is a feature in the physical /// environment that can be detected and tracked by an XR device. /// /// The raw, session-relative data type used to update this trackable. /// The concrete class which derives from . public class ARTrackable : ARTrackable where TSessionRelativeData : struct, ITrackable where TTrackable : ARTrackable { [SerializeField] [Tooltip("If true, this component's GameObject is destroyed when this trackable is removed.")] bool m_DestroyOnRemoval = true; /// /// If true, this component's GameObject will be removed immediately when the XR device reports this trackable is no longer tracked. /// /// /// Setting this to false will keep the GameObject around. You might want to do this, for example, /// if you have custom removal logic, such as a fade out. /// public bool destroyOnRemoval { get => m_DestroyOnRemoval; set => m_DestroyOnRemoval = value; } /// public override TrackableId trackableId => sessionRelativeData.trackableId; /// public override Pose pose => sessionRelativeData.pose; /// public override TrackingState trackingState => sessionRelativeData.trackingState; /// public override IntPtr nativePtr => sessionRelativeData.nativePtr; /// /// Pending means the trackable was added manually (usually via an AddTrackable-style method /// on its manager) but has not yet been reported as added. /// public bool pending { get; internal set; } /// /// The session-relative data associated with this trackable. /// protected internal TSessionRelativeData sessionRelativeData { get; private set; } /// /// Invoked just after the session-relative data has been set. /// The GameObject's transform has already been updated. /// You may override this method to perform further updates specific /// to the derived trackable. /// protected internal virtual void OnAfterSetSessionRelativeData() { } internal void SetSessionRelativeData(TSessionRelativeData data) => sessionRelativeData = data; } }