Class ARTrackableManager<TSubsystem, TSubsystemDescriptor, TProvider, TSessionRelativeData, TTrackable>
A base class for trackable managers. Trackable managers use data from tracking subsystems to create and maintain trackable components and their GameObjects. Refer to Trackables and trackable managers for more information.
Inheritance
Implements
Inherited Members
Namespace: UnityEngine.XR.ARFoundation
Assembly: Unity.XR.ARFoundation.dll
Syntax
[RequireComponent(typeof(XROrigin))]
[DisallowMultipleComponent]
public abstract class ARTrackableManager<TSubsystem, TSubsystemDescriptor, TProvider, TSessionRelativeData, TTrackable> : SubsystemLifecycleManager<TSubsystem, TSubsystemDescriptor, TProvider>, ITrackablesChanged<TTrackable> where TSubsystem : TrackingSubsystem<TSessionRelativeData, TSubsystem, TSubsystemDescriptor, TProvider>, new() where TSubsystemDescriptor : SubsystemDescriptorWithProvider<TSubsystem, TProvider> where TProvider : SubsystemProvider<TSubsystem> where TSessionRelativeData : struct, ITrackable where TTrackable : ARTrackable<TSessionRelativeData, TTrackable>
Type Parameters
Name | Description |
---|---|
TSubsystem | The tracking subsystem type. |
TSubsystemDescriptor | The subsystem descriptor type. |
TProvider | The subsystem provider type. |
TSessionRelativeData | The subsystem data type. |
TTrackable | The type of component that this component will manage (that is, create, update, and destroy). |
Fields
m_PendingAdds
A dictionary of trackables added via CreateTrackableImmediate(TSessionRelativeData) but not yet reported as added.
Declaration
protected Dictionary<TrackableId, TTrackable> m_PendingAdds
Field Value
Type | Description |
---|---|
Dictionary<TrackableId, TTrackable> |
m_Trackables
A dictionary of all trackables keyed by TrackableId
.
Declaration
protected Dictionary<TrackableId, TTrackable> m_Trackables
Field Value
Type | Description |
---|---|
Dictionary<TrackableId, TTrackable> |
Properties
gameObjectName
The name prefix that should be used when instantiating new GameObjects.
Declaration
protected abstract string gameObjectName { get; }
Property Value
Type | Description |
---|---|
string |
origin
The XR Origin component that will be used to instantiate detected trackables.
Declaration
protected XROrigin origin { get; }
Property Value
Type | Description |
---|---|
XROrigin |
trackables
A collection of all trackables managed by this component.
Declaration
public TrackableCollection<TTrackable> trackables { get; }
Property Value
Type | Description |
---|---|
TrackableCollection<TTrackable> |
trackablesChanged
Invoked when trackables have changed (been added, updated, or removed).
Declaration
public UnityEvent<ARTrackablesChangedEventArgs<TTrackable>> trackablesChanged { get; }
Property Value
Type | Description |
---|---|
UnityEvent<ARTrackablesChangedEventArgs<TTrackable>> |
Methods
Awake()
Saves a reference to the XR Origin component.
Declaration
protected virtual void Awake()
CanBeAddedToSubsystem(TTrackable)
Determines whether an existing ARTrackable<TSessionRelativeData, TTrackable> can be added to the underlying subsystem.
Declaration
protected bool CanBeAddedToSubsystem(TTrackable trackable)
Parameters
Type | Name | Description |
---|---|---|
TTrackable | trackable | An existing trackable to add to the subsystem. |
Returns
Type | Description |
---|---|
bool | Returns true if this manager is enabled, has a valid subsystem, and
|
Remarks
If trackable
has not been reported as added yet, and this component is either disabled or
does not have a valid subsystem, then the trackable
's
pending state is set to true.
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if |
CreateTrackableFromExisting(TTrackable, TSessionRelativeData)
Creates the native counterpart for an existing ARTrackable<TSessionRelativeData, TTrackable> added with a call to AddComponent, for example.
Declaration
protected void CreateTrackableFromExisting(TTrackable existingTrackable, TSessionRelativeData sessionRelativeData)
Parameters
Type | Name | Description |
---|---|---|
TTrackable | existingTrackable | The existing trackable component. |
TSessionRelativeData | sessionRelativeData | The AR data associated with the trackable. |
CreateTrackableImmediate(TSessionRelativeData)
Creates a TTrackable
immediately in a "pending" state.
The trackable will appear in the trackables collection immediately, but will not be reported
as added until the subsystem successfully adds it. This is useful for subsystems that deal
with trackables that can be both automatically detected and manually created.
Declaration
protected TTrackable CreateTrackableImmediate(TSessionRelativeData sessionRelativeData)
Parameters
Type | Name | Description |
---|---|---|
TSessionRelativeData | sessionRelativeData | The data associated with the trackable. |
Returns
Type | Description |
---|---|
TTrackable | A new trackable. |
DestroyPendingTrackable(TrackableId)
If the trackable with id trackableId
is in a "pending" state, and
destroyOnRemoval is true,
this method destroys the trackable's GameObject. Otherwise, this method has no effect.
Declaration
protected bool DestroyPendingTrackable(TrackableId trackableId)
Parameters
Type | Name | Description |
---|---|---|
TrackableId | trackableId | The id of the trackable to destroy. |
Returns
Type | Description |
---|---|
bool | true if the trackable was "pending" and is now destroyed. Otherwise, false. |
Remarks
This method will immediately remove a trackable only if it was created by CreateTrackableImmediate(TSessionRelativeData) and has not yet been reported as added by the subsystem.
This can happen if the trackable is created and removed within the same frame, as the subsystem might never have a chance to report its existence. Derived classes should use this if they support the concept of manual addition and removal of trackables.
GetPrefab()
The Prefab that should be instantiated when adding a trackable. Can be null
.
Declaration
protected virtual GameObject GetPrefab()
Returns
Type | Description |
---|---|
GameObject | The prefab should be instantiated when adding a trackable. |
OnAfterSetSessionRelativeData(TTrackable, TSessionRelativeData)
Invoked just after session-relative data has been set on a trackable.
Declaration
protected virtual void OnAfterSetSessionRelativeData(TTrackable trackable, TSessionRelativeData sessionRelativeData)
Parameters
Type | Name | Description |
---|---|---|
TTrackable | trackable | The trackable that has just been updated. |
TSessionRelativeData | sessionRelativeData | The session relative data used to update the trackable. |
OnCreateTrackable(TTrackable)
Invoked after creating the trackable. The trackable's sessionRelativeData will already be set.
Declaration
protected virtual void OnCreateTrackable(TTrackable trackable)
Parameters
Type | Name | Description |
---|---|---|
TTrackable | trackable | The newly created trackable. |
OnDisable()
Stops the TSubsystem
.
Declaration
protected override void OnDisable()
Overrides
OnEnable()
Creates the TSubsystem
.
Declaration
protected override void OnEnable()
Overrides
OnTrackablesChanged(List<TTrackable>, List<TTrackable>, List<TTrackable>)
Invoked when trackables have changed (that is, they were added, updated, or removed). Use this to perform additional logic, or to invoke public events related to your trackables.
Declaration
[Obsolete("OnTrackablesChanged() has been deprecated in AR Foundation version 6.0.", false)]
protected virtual void OnTrackablesChanged(List<TTrackable> added, List<TTrackable> updated, List<TTrackable> removed)
Parameters
Type | Name | Description |
---|---|---|
List<TTrackable> | added | A list of trackables added this frame. |
List<TTrackable> | updated | A list of trackables updated this frame. |
List<TTrackable> | removed | A list of trackables removed this frame. The trackable components are not destroyed until after this method returns. |
SetTrackablesActive(bool)
Iterates over every instantiated ARTrackable<TSessionRelativeData, TTrackable> and
activates or deactivates its GameObject based on the value of active
.
Declaration
public void SetTrackablesActive(bool active)
Parameters
Type | Name | Description |
---|---|---|
bool | active | If true, each trackable's GameObject is activated. Otherwise, they are deactivated. |
Update()
Update is called once per frame. This component first updates its internal state, then invokes the trackablesChanged event.
Declaration
protected virtual void Update()