/// <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); }
/// <summary> /// Creates a new cloud reference point using an existing local Reference Point. /// <example> /// The sample code below illustrates how to host a cloud reference point. /// <code> /// private ARCloudReferencePoint m_CloudReferencePoint; /// /// void HostCloudReference(Pose pose) /// { /// // Create a local Reference Point, you may also use another /// // Reference Point you may already have. /// ARReferencePoint localReferencePoint = /// ReferencePointManager.AddReferencePoint(pose); /// /// // Request the cloud reference point. /// m_CloudReferencePoint = /// ReferencePointManager.AddCloudReferencePoint(localReferencePoint); /// } /// /// void Update() /// { /// if (m_CloudReferencePoint) /// { /// // Check the cloud reference point state. /// CloudReferenceState cloudReferenceState = /// m_CloudReferencePoint.cloudReferenceState; /// if (cloudReferenceState == CloudReferenceState.Success) /// { /// myOtherGameObject.transform.SetParent /// m_CloudReferencePoint.transform, false); /// m_CloudReferencePoint = null; /// } /// else if (cloudReferenceState == CloudReferenceState.TaskInProgress) /// { /// // Wait, not ready yet. /// } /// else /// { /// // An error has occurred. /// } /// } /// } /// </code> /// </example> /// </summary> /// <param name="referencePointManager">The ReferencePointManager instance for extending. /// </param> /// <param name="referencePoint">The local <c>ARReferencePoint</c> to be used as the /// basis to host a new cloud reference point.</param> /// <returns>If successful, a <see cref="ARCloudReferencePoint"/>, /// otherwise <c>null</c>.</returns> public static ARCloudReferencePoint AddCloudReferencePoint( this ARReferencePointManager referencePointManager, ARReferencePoint 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); }