Class ARTrackableManager<TSubsystem, TSubsystemDescriptor, TSessionRelativeData, TTrackable>
A generic manager for components generated by features detected in the physical environment.
Inheritance
Inherited Members
Namespace: UnityEngine.XR.ARFoundation
Syntax
[RequireComponent(typeof(ARSessionOrigin))]
[DisallowMultipleComponent]
public abstract class ARTrackableManager<TSubsystem, TSubsystemDescriptor, TSessionRelativeData, TTrackable> : SubsystemLifecycleManager<TSubsystem, TSubsystemDescriptor> where TSubsystem : TrackingSubsystem<TSessionRelativeData, TSubsystemDescriptor> where TSubsystemDescriptor : SubsystemDescriptor<TSubsystem> where TSessionRelativeData : struct, ITrackable where TTrackable : ARTrackable<TSessionRelativeData, TTrackable>
Type Parameters
Name | Description |
---|---|
TSubsystem | The |
TSubsystemDescriptor | The |
TSessionRelativeData | A concrete struct used to hold data provided by the Subsystem. |
TTrackable | The type of component this component will manage (i.e., create, update, and destroy). |
Remarks
When the manager is informed that a trackable has been added, a new GameObject
is created with an ARTrackable
component on it. If
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 GameObject
s.
Declaration
protected abstract string gameObjectName { get; }
Property Value
Type | Description |
---|---|
String |
sessionOrigin
The ARSessionOrigin
which will be used to instantiate detected trackables.
Declaration
protected ARSessionOrigin sessionOrigin { get; }
Property Value
Type | Description |
---|---|
ARSessionOrigin |
trackables
A collection of all trackables managed by this component.
Declaration
public TrackableCollection<TTrackable> trackables { get; }
Property Value
Type | Description |
---|---|
TrackableCollection<TTrackable> |
Methods
Awake()
Invoked by Unity once when this component wakes up.
Declaration
protected virtual void Awake()
CreateTrackableImmediate(TSessionRelativeData)
Declaration
protected TTrackable CreateTrackableImmediate(TSessionRelativeData sessionRelativeData)
Parameters
Type | Name | Description |
---|---|---|
TSessionRelativeData | sessionRelativeData |
Returns
Type | Description |
---|---|
TTrackable |
DestroyPendingTrackable(TrackableId)
If in a "pending" state, the trackable with trackableId
's
GameObject
destroyed if
destroyOnRemoval is true.
Otherwise, this method has no effect.
Declaration
protected bool DestroyPendingTrackable(TrackableId trackableId)
Parameters
Type | Name | Description |
---|---|---|
TrackableId | trackableId |
Returns
Type | Description |
---|---|
Boolean |
|
Remarks
Trackables are usually removed only when the subsystem reports they have been removed during Update()
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 may 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, as there may not be a removal event if the trackable is added and removed quickly.
If the trackable is not in a pending state, i.e., it has already been reported as "added", then this method does nothing.
This method does not invoke OnTrackablesChanged(List<TTrackable>, List<TTrackable>, List<TTrackable>),
so no "removed" notifications will occur until the next call to Update() (and only if it was
previously reported as "added").
However, this method does invoke
GetPrefab()
The prefab that should be instantiated when adding a trackable.
Declaration
protected virtual GameObject GetPrefab()
Returns
Type | Description |
---|---|
GameObject |
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
property will already be set.
Declaration
protected virtual void OnCreateTrackable(TTrackable trackable)
Parameters
Type | Name | Description |
---|---|---|
TTrackable | trackable | The newly created trackable. |
OnTrackablesChanged(List<TTrackable>, List<TTrackable>, List<TTrackable>)
Invoked when trackables have changed, i.e., added, updated, or removed. Use this to perform additional logic, or to invoke public events related to your trackables.
Declaration
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(Boolean)
Iterates over every instantiated GameObject
based on the value of
active
.
This calls
GameObject.SetActive
on each trackable's GameObject
.
Declaration
public void SetTrackablesActive(bool active)
Parameters
Type | Name | Description |
---|---|---|
Boolean | active | If |
Update()
Update is called once per frame. This component's internal state
is first updated, and then the
Declaration
protected virtual void Update()