Class ARAnchorManager
Manages anchors.
Inheritance
Inherited Members
Namespace: UnityEngine.XR.ARFoundation
Syntax
[DefaultExecutionOrder(-2147483647)]
[DisallowMultipleComponent]
[RequireComponent(typeof(XROrigin))]
public sealed class ARAnchorManager : ARTrackableManager<XRAnchorSubsystem, XRAnchorSubsystemDescriptor, XRAnchorSubsystem.Provider, XRAnchor, ARAnchor>
Remarks
Use this component to programmatically add, remove, or query for
anchors. Anchors are Pose
s in the world
which will be periodically updated by an AR device as its understanding
of the world changes.
Subscribe to changes (added, updated, and removed) via the anchorsChanged event.
Properties
anchorPrefab
This prefab will be instantiated for each ARAnchor. May be null
.
Declaration
public GameObject anchorPrefab { get; set; }
Property Value
Type | Description |
---|---|
GameObject |
Remarks
The purpose of this property is to extend the functionality of ARAnchors. It is not the recommended way to instantiate content associated with an ARAnchor.
gameObjectName
The name to assign to the GameObject
instantiated for each ARAnchor.
Declaration
protected override string gameObjectName { get; }
Property Value
Type | Description |
---|---|
String |
Overrides
Methods
AddAnchor(Pose)
Attempts to add an ARAnchor with the given Pose
.
Declaration
[Obsolete("Add an anchor using AddComponent<ARAnchor>(). (2020-10-06)")]
public ARAnchor AddAnchor(Pose pose)
Parameters
Type | Name | Description |
---|---|---|
Pose | pose | The pose, in Unity world space, of the ARAnchor. |
Returns
Type | Description |
---|---|
ARAnchor | A new ARAnchor if successful, otherwise |
Remarks
If GetPrefab()
is not null, a new instance of that prefab will be instantiated. Otherwise, a
new GameObject
will be created. In either case, the resulting
GameObject
will have an ARAnchor component on it.
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this |
InvalidOperationException | Thrown if the underlying subsystem is |
AttachAnchor(ARPlane, Pose)
Attempts to create a new anchor that is attached to an existing ARPlane.
Declaration
public ARAnchor AttachAnchor(ARPlane plane, Pose pose)
Parameters
Type | Name | Description |
---|---|---|
ARPlane | plane | The ARPlane to which to attach. |
Pose | pose | The initial |
Returns
Type | Description |
---|---|
ARAnchor | A new ARAnchor if successful, otherwise |
GetAnchor(TrackableId)
Gets the ARAnchor with given trackableId
,
or null
if it does not exist.
Declaration
public ARAnchor GetAnchor(TrackableId trackableId)
Parameters
Type | Name | Description |
---|---|---|
TrackableId | trackableId | The TrackableId of the ARAnchor to retrieve. |
Returns
Type | Description |
---|---|
ARAnchor | The ARAnchor with |
GetPrefab()
Get the prefab to instantiate for each ARAnchor.
Declaration
protected override GameObject GetPrefab()
Returns
Type | Description |
---|---|
GameObject | The prefab to instantiate for each ARAnchor. |
Overrides
OnTrackablesChanged(List<ARAnchor>, List<ARAnchor>, List<ARAnchor>)
Invoked when the base class detects trackable changes.
Declaration
protected override void OnTrackablesChanged(List<ARAnchor> added, List<ARAnchor> updated, List<ARAnchor> removed)
Parameters
Type | Name | Description |
---|---|---|
List<ARAnchor> | added | The list of added anchors. |
List<ARAnchor> | updated | The list of updated anchors. |
List<ARAnchor> | removed | The list of removed anchors. |
Overrides
RemoveAnchor(ARAnchor)
Attempts to remove an ARAnchor.
Declaration
[Obsolete("Call Destroy() on the ARAnchor component to remove it. (2020-10-06)")]
public bool RemoveAnchor(ARAnchor anchor)
Parameters
Type | Name | Description |
---|---|---|
ARAnchor | anchor | The anchor you wish to remove. |
Returns
Type | Description |
---|---|
Boolean |
|
Events
anchorsChanged
Invoked once per frame to communicate changes to anchors, including new anchors, the update of existing anchors, and the removal of previously existing anchors.
Declaration
public event Action<ARAnchorsChangedEventArgs> anchorsChanged
Event Type
Type | Description |
---|---|
Action<ARAnchorsChangedEventArgs> |