0

我开发了一个统一的应用程序,我正在使用天蓝色的空间锚。我发现无法更新已经存在的 cloudAnchor。我试过这个:

    protected virtual async Task SaveCurrentObjectAnchorToCloudAsync()
    {
        // Get the cloud-native anchor behavior
        CloudNativeAnchor cna = cubeInstance.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;

        // In this sample app we delete the cloud anchor explicitly, but here we show how to set an anchor to expire automatically
        //cloudAnchor.Expiration = DateTimeOffset.Now.AddDays(7);

        while (!CloudManager.IsReadyForCreate)
        {
            await Task.Delay(330);
            float createProgress = CloudManager.SessionStatus.RecommendedForCreateProgress;
            Debug.Log("create Progress");
            Debug.Log(createProgress);

            if(createProgress > 1)
            {
                createProgress = 1;
            }

            feedbackText.text = $"{ createProgress: 0 %}";
            Debug.Log($"Move your device to capture more environment data: {createProgress:0%}");
        }

        bool success = false;

        feedbackText.text = "Saving...";

        try
        {
            if(currentCloudAnchor == null)
            {
                // Actually save
                await CloudManager.CreateAnchorAsync(cloudAnchor);
            } else {
                await CloudManager.Session.UpdateAnchorPropertiesAsync(cloudAnchor);
            }

            // 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)
        {
            OnSaveCloudAnchorFailed(ex);
        }
    }

该方法的第一次调用正在工作。在蔚蓝的云中创建了一个 spartialAnchor。在第二次调用中,当我想更新锚时,我首先 git 错误:

InvalidOperationException:SpatialAnchor::SetExpirationUtcTimeMS 不能用于在 SpatialAnchor 保存到云端后更改过期时间。目前不支持该功能。请求简历:。回复简历:。08-18 01:07:09.845 31868 31927 E Unity:在 Microsoft.Azure.SpatialAnchors.NativeLibraryHelpers.CheckStatus(System.IntPtr 句柄,Microsoft.Azure.SpatialAnchors.status 值)[0x00109] 在 C:...\Assets\ AzureSpatialAnchors.SDK\Plugins\Common\AzureSpatialAnchorsBridge.cs:5381

为了摆脱它,我不得不删除这一行:

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

但是云主播的更新还是不行。我收到此错误:

OnError - 指定的空间锚点已与不同的商店关联

我也尝试使用这条线进行更新

await CloudManager.CreateAnchorAsync(cloudAnchor);

我收到此错误:

无法保存锚点 System.InvalidOperationException: 。要求简历:。回复简历:。08-18 01:20:07.661 5849 5909 I Unity:在 Microsoft.Azure.SpatialAnchors.NativeLibraryHelpers.CheckStatus(System.IntPtr 句柄,Microsoft.Azure.SpatialAnchors.status 值)[0x00109] 在 C:...\Assets\ AzureSpatialAnchors.SDK\Plugins\Common\AzureSpatialAnchorsBridge.cs:5381 08-18 01:20:07.661 5849 5909 I Unity:在 Microsoft.Azure.SpatialAnchors.CloudSpatialAnchorSession+<>c__DisplayClass71_0.b__0 () [0x00001] 在 C:\Users\ ppelluda\Documents\Projects\shared-experiences-tests\Assets\AzureSpatialAnchors.SDK\Plugins\Common\AzureSpatialAnchorsBridge.cs:7162

此刻,我只看到删除 azure 中当前的 spatialAnchor 并创建一个新的选项。这不可能是正确的方法。

更新锚点的正确方法是什么?

4

1 回答 1

0

这个问题/问题之前已经提出过,所以我可以更新你的答案。目前没有办法更新已经存在的锚。您将需要删除旧锚并创建一个新锚。

于 2019-08-21T13:11:34.350 回答