Google is committed to advancing racial equity for Black communities. See how.

Google.XR.ARCoreExtensions.ARAnchorManagerExtensions

Extensions to AR Foundation's ARAnchorManager class.

Summary

Public static functions

AddCloudReferencePoint(this ARAnchorManager referencePointManager, ARAnchor referencePoint) Deprecated. Please use HostCloudAnchor(ARAnchor) instead.
Creates a new cloud reference point using an existing local Reference Point.
HostCloudAnchor(this ARAnchorManager anchorManager, ARAnchor anchor)
Creates a new Cloud Anchor using an existing local ARAnchor.
ResolveCloudAnchorId(this ARAnchorManager anchorManager, string cloudAnchorId)
Creates a new local Cloud Anchor from the provided Id.
ResolveCloudReferenceId(this ARAnchorManager referencePointManager, string cloudReferenceId) Deprecated. Please use ResolveCloudAnchorId(string) instead.
Creates a new local cloud reference point from the provided Id.

Public static functions

AddCloudReferencePoint

ARCloudReferencePoint AddCloudReferencePoint(
  this ARAnchorManager referencePointManager,
  ARAnchor referencePoint
)

Creates a new cloud reference point using an existing local Reference Point.

Deprecated. Please use HostCloudAnchor(ARAnchor) instead.

Details
Parameters
referencePointManager
The ARAnchorManager instance.
referencePoint
The local ARAnchor to be used as the basis to host a new cloud reference point.
Returns
If successful, a ARCloudReferencePoint, otherwise null.

HostCloudAnchor

ARCloudAnchor HostCloudAnchor(
  this ARAnchorManager anchorManager,
  ARAnchor anchor
)

Creates a new Cloud Anchor using an existing local ARAnchor.

The sample code below illustrates how to host a Cloud Anchor.


private ARCloudAnchor m_CloudAnchor;

void HostCloudAnchor(Pose pose)
{
    // Create a local anchor, you may also use another ARAnchor you already have.
    ARAnchor localAnchor = AnchorManager.AddAnchor(pose);

    // Request the Cloud Anchor.
    m_CloudAnchor = AnchorManager.HostCloudAnchor(localAnchor);
}

void Update()
{
    if (m_CloudAnchor)
    {
        // Check the Cloud Anchor state.
        CloudAnchorState cloudAnchorState = m_CloudAnchor.cloudAnchorState;
        if (cloudAnchorState == CloudAnchorState.Success)
        {
            myOtherGameObject.transform.SetParent(m_CloudAnchor.transform, false);
            m_CloudAnchor = null;
        }
        else if (cloudAnchorState == CloudAnchorState.TaskInProgress)
        {
            // Wait, not ready yet.
        }
        else
        {
            // An error has occurred.
        }
    }
}

Details
Parameters
anchorManager
The ARAnchorManager instance.
anchor
The local ARAnchor to be used as the basis to host a new Cloud Anchor.
Returns
If successful, a ARCloudAnchor, otherwise null.

ResolveCloudAnchorId

ARCloudAnchor ResolveCloudAnchorId(
  this ARAnchorManager anchorManager,
  string cloudAnchorId
)

Creates a new local Cloud Anchor from the provided Id.

The sample code below illustrates how to resolve a Cloud Anchor.


private ARCloudAnchor m_CloudAnchor;

void ResolveCloudAnchor(string cloudAnchorId)
{
    // Request the Cloud Anchor.
    m_CloudAnchor = AnchorManager.ResolveCloudAnchorId(cloudAnchorId);
}

void Update()
{
    if (m_CloudAnchor)
    {
        // Check the Cloud Anchor state.
        CloudAnchorState cloudAnchorState = m_CloudAnchor.cloudAnchorState;
        if (cloudAnchorState == CloudAnchorState.Success)
        {
            myOtherGameObject.transform.SetParent(m_CloudAnchor.transform, false);
            m_CloudAnchor = null;
        }
        else if (cloudAnchorState == CloudAnchorState.TaskInProgress)
        {
            // Wait, not ready yet.
        }
        else
        {
            // An error has occurred.
        }
    }
}

Details
Parameters
anchorManager
The ARAnchorManager instance.
cloudAnchorId
String representing the Cloud Anchor.
Returns
If successful, a ARCloudAnchor, otherwise null.

ResolveCloudReferenceId

ARCloudReferencePoint ResolveCloudReferenceId(
  this ARAnchorManager referencePointManager,
  string cloudReferenceId
)

Creates a new local cloud reference point from the provided Id.

Deprecated. Please use ResolveCloudAnchorId(string) instead.

Details
Parameters
referencePointManager
The ARAnchorManager instance.
cloudReferenceId
String representing the cloud reference.
Returns
If successful, a ARCloudReferencePoint, otherwise null.