/// <summary>
        /// Moves the specified anchored object.
        /// </summary>
        /// <param name="objectToMove">The anchored object to move.</param>
        /// <param name="worldPos">The world position.</param>
        /// <param name="worldRot">The world rotation.</param>
        /// <param name="cloudSpatialAnchor">The cloud spatial anchor.</param>
        protected virtual void MoveAnchoredObject(GameObject objectToMove, Vector3 worldPos, Quaternion worldRot, CloudSpatialAnchor cloudSpatialAnchor = null)
        {
            // Get the cloud-native anchor behavior
            CloudNativeAnchor cna = objectToMove.GetComponent <CloudNativeAnchor>();

            // Warn and exit if the behavior is missing
            if (cna == null)
            {
                Debug.LogWarning($"The object {objectToMove.name} is missing the {nameof(CloudNativeAnchor)} behavior.");
                return;
            }

            // Is there a cloud anchor to apply
            if (cloudSpatialAnchor != null)
            {
                // Yes. Apply the cloud anchor, which also sets the pose.
                Debug.Log("!!!!!! MoveAnchoredObject (1)");
                cna.CloudToNative(cloudSpatialAnchor);
            }
            else
            {
                // No. Just set the pose.
                Debug.Log("!!!!!! MoveAnchoredObject (2)");
                cna.SetPose(worldPos, worldRot);
            }
        }
 public void MovePlacingAnchor(Vector3 position)
 {
     if (_placingAnchor == null)
     {
         throw new ArgumentNullException(nameof(_placingAnchor));
     }
     _placingAnchor.SetPose(new Pose(position, Quaternion.identity));
 }
Esempio n. 3
0
    protected virtual async Task SaveCurrentObjectAnchorToCloudAsync()
    {
        CloudNativeAnchor nativeAnchor = this.GetComponent <CloudNativeAnchor>();

        nativeAnchor.SetPose(this.transform.position, this.transform.rotation);

        // If the cloud portion of the anchor hasn't been created yet, create it
        if (nativeAnchor.CloudAnchor == null)
        {
            nativeAnchor.NativeToCloud();
        }

        CloudSpatialAnchor cloudAnchor = nativeAnchor.CloudAnchor;

        cloudAnchor.Expiration = DateTimeOffset.Now.AddDays(7);

        while (!GetComponent <SpatialAnchorManager>().IsReadyForCreate)
        {
            await Task.Delay(330);

            float createProgress = GetComponent <SpatialAnchorManager>().SessionStatus.RecommendedForCreateProgress;
            feedback.text = $"Move your device to capture more environment data: {createProgress:0%}";
        }

        Pose anchorPose = cloudAnchor.GetPose();

        feedback.text = "Anchor Position: " + anchorPose.position + " Rotation: " + anchorPose.rotation;


        try
        {
            // Actually save
            await GetComponent <SpatialAnchorManager>().CreateAnchorAsync(cloudAnchor);

            feedback.text = "Saved: " + cloudAnchor.Identifier;
            // Store
            currentCloudAnchor = cloudAnchor;

            //    // Success?
            //    success = currentCloudAnchor != null;

            //    if (success && !isErrorActive)
            //    {
            //        // Await override, which may perform additional tasks
            //        // such as storing the key in the AnchorExchanger
            //        await OnSaveCloudAnchorSuccessfulAsync();
            //    }
            //    else
            //    {
            //        OnSaveCloudAnchorFailed(new Exception("Failed to save, but no exception was thrown."));
            //    }
        }
        catch (Exception ex)
        {
            feedback.text = ex.ToString();
            //    OnSaveCloudAnchorFailed(ex);
        }
    }