/// <summary> /// Creates a new Cloud Anchor using an existing local ARAnchor. /// <example> /// The sample code below illustrates how to host a Cloud Anchor. /// <pre> /// <code> /// private ARCloudAnchor _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. /// _cloudAnchor = AnchorManager.HostCloudAnchor(localAnchor); /// } /// /// void Update() /// { /// if (_cloudAnchor) /// { /// // Check the Cloud Anchor state. /// CloudAnchorState cloudAnchorState = _cloudAnchor.cloudAnchorState; /// if (cloudAnchorState == CloudAnchorState.Success) /// { /// myOtherGameObject.transform.SetParent(_cloudAnchor.transform, false); /// _cloudAnchor = null; /// } /// else if (cloudAnchorState == CloudAnchorState.TaskInProgress) /// { /// // Wait, not ready yet. /// } /// else /// { /// // An error has occurred. /// } /// } /// } /// </code> /// </pre> /// </example> /// </summary> /// <param name="anchorManager">The ARAnchorManager instance.</param> /// <param name="anchor">The local <c>ARAnchor</c> to be used as the /// basis to host a new Cloud Anchor.</param> /// <returns>If successful, a <c><see cref="ARCloudAnchor"/></c>, /// otherwise <c>null</c>.</returns> public static ARCloudAnchor HostCloudAnchor( this ARAnchorManager anchorManager, ARAnchor anchor) { // Create the underlying ARCore Cloud Anchor. IntPtr cloudAnchorHandle = SessionApi.HostCloudAnchor( ARCoreExtensions._instance.currentARCoreSessionHandle, anchor.AnchorHandle()); if (cloudAnchorHandle == IntPtr.Zero) { return(null); } // Create the GameObject that is the Cloud Anchor. ARCloudAnchor cloudAnchor = (new GameObject(_gameObjectName)).AddComponent <ARCloudAnchor>(); if (cloudAnchor) { cloudAnchor.SetAnchorHandle(cloudAnchorHandle); } // Parent the new Cloud Anchor to the session origin. cloudAnchor.transform.SetParent( ARCoreExtensions._instance.SessionOrigin.trackablesParent, false); return(cloudAnchor); }
public static ARCloudReferencePoint AddCloudReferencePoint( this ARAnchorManager referencePointManager, ARAnchor referencePoint) { // Create the underlying ARCore Cloud Anchor. IntPtr cloudAnchorHandle = SessionApi.HostCloudAnchor( ARCoreExtensions.Instance.CurrentARCoreSessionHandle, referencePoint.AnchorHandle()); if (cloudAnchorHandle == IntPtr.Zero) { return(null); } // Create the GameObject that is the cloud reference point. ARCloudReferencePoint cloudReferencePoint = (new GameObject(k_GameObjectName)).AddComponent <ARCloudReferencePoint>(); if (cloudReferencePoint) { cloudReferencePoint.SetAnchorHandle(cloudAnchorHandle); } // Parent the new cloud reference point to the session origin. cloudReferencePoint.transform.SetParent( ARCoreExtensions.Instance.SessionOrigin.trackablesParent, false); return(cloudReferencePoint); }
/// <summary> /// Creates a new Cloud Anchor with a given lifetime using an existing local ARAnchor. /// </summary> /// <param name="anchorManager">The ARAnchorManager instance.</param> /// <param name="anchor">The local <c>ARAnchor</c> to be used as the /// basis to host a new Cloud Anchor.</param> /// <param name="ttlDays">The lifetime of the anchor in days. Must be positive. The /// maximum allowed value is 1 if using an API Key to authenticate with the /// ARCore Cloud Anchor service, otherwise the maximum allowed value is 365.</param> /// <returns>If successful, an <c><see cref="ARCloudAnchor"/></c>, /// otherwise <c>null</c>.</returns> public static ARCloudAnchor HostCloudAnchor( this ARAnchorManager anchorManager, ARAnchor anchor, int ttlDays) { if (ttlDays <= 0 || ttlDays > 365) { Debug.LogErrorFormat("Failed to host a Cloud Anchor with invalid TTL {0}. " + "The lifetime of the anchor in days must be positive, " + "the maximum allowed value is 1 when using an API Key to authenticate with " + "the ARCore Cloud Anchor service, otherwise the maximum allowed value is 365.", ttlDays); return(null); } // Create the underlying ARCore Cloud Anchor with given ttlDays. IntPtr cloudAnchorHandle = SessionApi.HostCloudAnchor( ARCoreExtensions._instance.currentARCoreSessionHandle, anchor.AnchorHandle(), ttlDays); if (cloudAnchorHandle == IntPtr.Zero) { return(null); } // Create the GameObject that is the Cloud Anchor. ARCloudAnchor cloudAnchor = new GameObject(_gameObjectName).AddComponent <ARCloudAnchor>(); if (cloudAnchor) { cloudAnchor.SetAnchorHandle(cloudAnchorHandle); } // Parent the new Cloud Anchor to the session origin. cloudAnchor.transform.SetParent( ARCoreExtensions._instance.SessionOrigin.trackablesParent, false); return(cloudAnchor); }