Class ARTrackedImageManager
A manager for ARTrackedImages. Uses the XRImageTrackingSubsystem
to recognize and track 2D images in the physical environment.
Inheritance
Inherited Members
Namespace: UnityEngine.XR.ARFoundation
Syntax
[DefaultExecutionOrder(-2147483647)]
[RequireComponent(typeof(ARSessionOrigin))]
[HelpURL("https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.0/api/UnityEngine.XR.ARFoundation.ARTrackedImageManager.html")]
public sealed class ARTrackedImageManager : ARTrackableManager<XRImageTrackingSubsystem, XRImageTrackingSubsystemDescriptor, XRTrackedImage, ARTrackedImage>
Properties
currentMaxNumberOfMovingImages
Get the maximum number of moving images to track in realtime currently in use by the subsystem.
Declaration
public int currentMaxNumberOfMovingImages { get; }
Property Value
Type | Description |
---|---|
Int32 |
gameObjectName
The name to be used for the GameObject
whenever a new image is detected.
Declaration
protected override string gameObjectName { get; }
Property Value
Type | Description |
---|---|
String |
Overrides
maxNumberOfMovingImages
The maximum number of moving images to track in realtime. This property is obsolete. Use requestedMaxNumberOfMovingImages or currentMaxNumberOfMovingImages instead.
Declaration
[Obsolete("Use requestedMaxNumberOfMovingImages or currentMaxNumberOfMovingImages instead. (2020-01-16)")]
public int maxNumberOfMovingImages { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
referenceLibrary
Get or set the reference image library, the set of images to search for in the physical environment.
Declaration
public IReferenceImageLibrary referenceLibrary { get; set; }
Property Value
Type | Description |
---|---|
IReferenceImageLibrary |
Remarks
An IReferenceImageLibrary
can be either an XRReferenceImageLibrary
or a RuntimeReferenceImageLibrary
. XRReferenceImageLibrary
s can only be
constructed at edit-time and are immutable at runtime. A RuntimeReferenceImageLibrary
is the runtime representation of a XRReferenceImageLibrary
and may be mutable
at runtime (see MutableRuntimeReferenceImageLibrary
).
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the referenceLibrary is set to |
requestedMaxNumberOfMovingImages
The requested maximum number of moving images to track in realtime. Support may vary between devices and providers. Check
for support at runtime with descriptor's
supportsMovingImages
property.
Declaration
public int requestedMaxNumberOfMovingImages { get; set; }
Property Value
Type | Description |
---|---|
Int32 |
trackedImagePrefab
If not null, instantiates this prefab for each detected image.
Declaration
public GameObject trackedImagePrefab { get; set; }
Property Value
Type | Description |
---|---|
GameObject |
Remarks
The purpose of this property is to extend the functionality of ARTrackedImages. It is not the recommended way to instantiate content associated with an ARTrackedImage. See Tracked Image Prefab for more details.
Methods
CreateRuntimeLibrary(XRReferenceImageLibrary)
Creates a UnityEngine.XR.ARSubsystems.RuntimeReferenceImageLibrary
from an existing
UnityEngine.XR.ARSubsystems.XRReferenceImageLibrary
or an empty library if serializedLibrary
is null
.
Use this to construct reference image libraries at runtime. If the library is of type
MutableRuntimeReferenceImageLibrary
, it is modifiable at runtime.
Declaration
public RuntimeReferenceImageLibrary CreateRuntimeLibrary(XRReferenceImageLibrary serializedLibrary = null)
Parameters
Type | Name | Description |
---|---|---|
XRReferenceImageLibrary | serializedLibrary | An existing |
Returns
Type | Description |
---|---|
RuntimeReferenceImageLibrary | A new |
Exceptions
Type | Condition |
---|---|
NotSupportedException | Thrown if there is no subsystem. This usually means image tracking is not supported. |
GetPrefab()
Get the prefab that will be instantiated for each ARTrackedImage.
Declaration
protected override GameObject GetPrefab()
Returns
Type | Description |
---|---|
GameObject | The prefab that will be instantiated for each ARTrackedImage. |
Overrides
OnAfterSetSessionRelativeData(ARTrackedImage, XRTrackedImage)
Invoked just after updating each ARTrackedImage. Used to update the referenceImage.
Declaration
protected override void OnAfterSetSessionRelativeData(ARTrackedImage image, XRTrackedImage sessionRelativeData)
Parameters
Type | Name | Description |
---|---|---|
ARTrackedImage | image | The tracked image being updated. |
XRTrackedImage | sessionRelativeData | New data associated with the tracked image. Spatial data is relative to the ARSessionOrigin. |
Overrides
OnBeforeStart()
Sets the image library on the subsystem before Start() is called on the XRImageTrackingSubsystem
.
Declaration
protected override void OnBeforeStart()
Overrides
OnTrackablesChanged(List<ARTrackedImage>, List<ARTrackedImage>, List<ARTrackedImage>)
Invokes the trackedImagesChanged event.
Declaration
protected override void OnTrackablesChanged(List<ARTrackedImage> added, List<ARTrackedImage> updated, List<ARTrackedImage> removed)
Parameters
Type | Name | Description |
---|---|---|
List<ARTrackedImage> | added | A list of images added this frame. |
List<ARTrackedImage> | updated | A list of images updated this frame. |
List<ARTrackedImage> | removed | A list of images removed this frame. |
Overrides
Events
trackedImagesChanged
Invoked once per frame with information about the ARTrackedImages that have changed, i.e., been added, updated, or removed.
This happens just before ARTrackedImages are destroyed, so you can set ARTrackedImage.destroyOnRemoval
to false
from this event to suppress this behavior.
Declaration
public event Action<ARTrackedImagesChangedEventArgs> trackedImagesChanged
Event Type
Type | Description |
---|---|
Action<ARTrackedImagesChangedEventArgs> |