1

我正在尝试使用Unity 2019.4.19f1Azure Spatial Anchor构建 AR Android应用程序,以便将锚点保存到云中。

我正在使用演示中给出的SpatialAnchorManager类。创建并启动会话后,我尝试使用以下方法将预制件保存到云中,但CloudManager.SessionStatus.RecommendedForCreateProgress永远不会超过 0。

protected virtual async Task SaveCurrentObjectAnchorToCloudAsync(GameObject spawnedObject)
    {
        CloudNativeAnchor cna = spawnedObject.GetComponent<CloudNativeAnchor>();

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

        // Get the cloud portion of the anchor
        CloudSpatialAnchor cloudAnchor = cna.CloudAnchor;

        while (!CloudManager.IsReadyForCreate)
        {
            await Task.Delay(330);
            float createProgress = CloudManager.SessionStatus.RecommendedForCreateProgress;
            feedBack.text = $"Move your device to capture more environment data: {createProgress}";
        }
        bool success = false;

        feedBack.text = "Saving...";

        try
        {
            await CloudManager.CreateAnchorAsync(cloudAnchor);
            var currentCloudAnchor = cloudAnchor;
            success = currentCloudAnchor != null;

            if (success && !isErrorActive)
            {
                await OnSaveCloudAnchorSuccessfulAsync();
            }
            else
            {
                OnSaveCloudAnchorFailed(new Exception("Failed to save, but no exception was thrown."));
            }
        }
        catch (Exception ex)
        {
            OnSaveCloudAnchorFailed(ex);
        }
    }
4

0 回答 0