Пример #1
0
        private void AnchorLookedUp(string anchorId)
        {
            this.DestroySession();

            this.cloudAnchorManager = new AzureSpatialAnchorsManager(this.sceneView.Session);
            this.cloudAnchorManager.OnAnchorLocated += (sender, args) =>
                                                       this.RunOnUiThread(() =>
            {
                CloudSpatialAnchor anchor = args.Args.Anchor;
                LocateAnchorStatus status = args.Args.Status;

                if (status == LocateAnchorStatus.AlreadyTracked || status == LocateAnchorStatus.Located)
                {
                    AnchorVisual foundVisual = new AnchorVisual(anchor.LocalAnchor)
                    {
                        CloudAnchor = anchor
                    };
                    foundVisual.AnchorNode.SetParent(this.arFragment.ArSceneView.Scene);
                    string cloudAnchorIdentifier = foundVisual.CloudAnchor.Identifier;
                    foundVisual.SetColor(foundColor);
                    foundVisual.Render(this.arFragment);
                    this.textView.Text = foundVisual.CloudAnchor.AppProperties["Label"];
                }
            });

            this.cloudAnchorManager.StartSession();
            AnchorLocateCriteria criteria = new AnchorLocateCriteria();

            criteria.SetIdentifiers(new string[] { anchorId });
            this.cloudAnchorManager.StartLocating(criteria);
        }
Пример #2
0
        private Anchor CreateAnchor(HitResult hitResult)
        {
            AnchorVisual visual = new AnchorVisual(hitResult.CreateAnchor());

            visual.SetColor(readyColor);
            visual.Render(this.arFragment);
            this.anchorVisuals[string.Empty] = visual;

            this.RunOnUiThread(() =>
            {
                this.scanProgressText.Visibility = ViewStates.Visible;
                if (this.enoughDataForSaving)
                {
                    if (visual == null)
                    {
                        return;
                    }

                    if (!this.enoughDataForSaving)
                    {
                        return;
                    }

                    this.RunOnUiThread(() => this.exitButton.Visibility = ViewStates.Gone);

                    this.SetupLocalCloudAnchor(visual);

                    Task.Run(async() =>
                    {
                        try
                        {
                            CloudSpatialAnchor result = await this.cloudAnchorManager.CreateAnchorAsync(visual.CloudAnchor);
                            this.AnchorSaveSuccess(result);
                        }
                        catch (CloudSpatialException ex)
                        {
                            this.AnchorSaveFailed($"{ex.Message}, {ex.ErrorCode}");
                        }
                        catch (Exception ex)
                        {
                            this.AnchorSaveFailed(ex.Message);
                        }
                    });

                    lock (this.progressLock)
                    {
                        this.RunOnUiThread(() =>
                        {
                            this.scanProgressText.Visibility = ViewStates.Gone;
                            this.scanProgressText.Text       = string.Empty;
                            this.textView.Text = "Saving cloud anchor...";
                        });
                    }
                }
                else
                {
                    this.textView.Text = "Move around the anchor";
                }
            });
            this.exitButton.Visibility = ViewStates.Visible;
            return(visual.LocalAnchor);
        }