Exemplo n.º 1
0
    /// <summary>
    /// Method to locate nearby anchors given a already located one
    /// </summary>
    /// <param name="anchor"> alredy located anchor </param>
    public void LocateNearByAnchors(CloudSpatialAnchor anchor)
    {
        // for locating nearby anchors
        SetGraphEnabled(true, true);
        // make sure it doesn't search for ID
        anchorLocateCriteria.Identifiers = new string[0];

        NearAnchorCriteria nearAnchorCriteria = new NearAnchorCriteria();

        nearAnchorCriteria.SourceAnchor     = anchor;
        nearAnchorCriteria.DistanceInMeters = findNearRadius;
        nearAnchorCriteria.MaxResultCount   = maxNumberOfNearAnchor;
        anchorLocateCriteria.NearAnchor     = nearAnchorCriteria;

        if ((cloudManager != null) && (cloudManager.Session != null))
        {
            currentWatcher = cloudManager.Session.CreateWatcher(anchorLocateCriteria);
            Debug.Log("Watcher created");
            Debug.Log("Looking for Azure anchor... please wait...");
        }
        else
        {
            Debug.Log("Attempt to create watcher failed, no session exists");
            currentWatcher = null;
        }
    }
Exemplo n.º 2
0
        public void SetNearbyAnchor(CloudSpatialAnchor nearbyAnchor, float DistanceInMeters, int MaxNearAnchorsToFind)
        {
            if (nearbyAnchor == null)
            {
                anchorLocateCriteria.NearAnchor = new NearAnchorCriteria();
                return;
            }

            NearAnchorCriteria nac = new NearAnchorCriteria();

            nac.SourceAnchor                = nearbyAnchor;
            nac.DistanceInMeters            = DistanceInMeters;
            nac.MaxResultCount              = MaxNearAnchorsToFind;
            anchorLocateCriteria.NearAnchor = nac;
        }
Exemplo n.º 3
0
    public void SetNearbyAnchor(CloudSpatialAnchor SourceAnchor, float DistanceInMeters = 5.0f, int MaxResultCount = 20)
    {
        if (SourceAnchor == null)
        {
            anchorLocateCriteria.NearAnchor = new NearAnchorCriteria();
            return;
        }

        NearAnchorCriteria nearAnchorCriteria = new NearAnchorCriteria();

        nearAnchorCriteria.SourceAnchor     = SourceAnchor;
        nearAnchorCriteria.DistanceInMeters = DistanceInMeters;
        nearAnchorCriteria.MaxResultCount   = MaxResultCount;
        anchorLocateCriteria.NearAnchor     = nearAnchorCriteria;
    }
        public void LookForNearbyAnchors()
        {
            AnchorLocateCriteria criteria     = new AnchorLocateCriteria();
            NearAnchorCriteria   nearCriteria = new NearAnchorCriteria
            {
                DistanceInMeters = 5,
                SourceAnchor     = this.anchorVisuals[this.targetId].cloudAnchor
            };

            criteria.NearAnchor = nearCriteria;

            // Cannot run more than one watcher concurrently
            this.StopLocating();

            this.cloudSession.CreateWatcher(criteria);

            this.UpdateMainStatusTitle("Locating Nearby Anchors ....");
        }
Exemplo n.º 5
0
    public void LocateNearByAnchors(CloudSpatialAnchor anchor)
    {
        NearAnchorCriteria nearAnchorCriteria = new NearAnchorCriteria();

        nearAnchorCriteria.SourceAnchor     = anchor;
        nearAnchorCriteria.DistanceInMeters = 10;
        nearAnchorCriteria.MaxResultCount   = 2; // max anchor to find
        anchorLocateCriteria.NearAnchor     = nearAnchorCriteria;

        if ((cloudManager != null) && (cloudManager.Session != null))
        {
            currentWatcher = cloudManager.Session.CreateWatcher(anchorLocateCriteria);
            Debug.Log("Watcher created");
            Debug.Log("Looking for Azure anchor... please wait...");
        }
        else
        {
            Debug.Log("Attempt to create watcher failed, no session exists");
            currentWatcher = null;
        }
    }
        private async UniTask LocateNearAnchorsTask(CloudSpatialAnchor sourceAnchor, int count)
        {
            var nearAnchorCriteria = new NearAnchorCriteria()
            {
                SourceAnchor = sourceAnchor
            };

            var watcher = _spatialAnchorManager.Session.CreateWatcher(
                new AnchorLocateCriteria()
            {
                NearAnchor = nearAnchorCriteria,
                Strategy   = LocateStrategy.Relationship
            });

            var detectedAnchorCount = 0;

            _instructionUIPresenter.UpdateMessage($"アンカーを接続情報から検知中... {detectedAnchorCount}/{count}");

            var detectedAnchors = await Observable.FromEvent <AnchorLocatedDelegate, AnchorLocatedEventArgs>(
                h => (sender, e) => h.Invoke(e),
                h => _spatialAnchorManager.AnchorLocated += h,
                h => _spatialAnchorManager.AnchorLocated -= h)
                                  .Where(e => e.Status == LocateAnchorStatus.Located)
                                  .Distinct(f => f.Identifier)
                                  .ObserveOnMainThread()
                                  .Do(e =>
            {
                detectedAnchorCount++;
                _instructionUIPresenter.UpdateMessage($"アンカーを接続情報から検知中... {detectedAnchorCount}/{count}");
                _anchorObjectPresenter.RestoreAnchorObject(e.Anchor, Color.blue, new Vector3(0.2f, 0.08f, 0.08f));
            })
                                  .Take(count)
                                  .ToArray();

            watcher.Stop();
            _instructionUIPresenter.UpdateMessage($"{detectedAnchors.Length}個の全てのアンカーを検知しました!");
            await _instructionUIPresenter.OnTriggerProceed().First();
        }
        private async UniTask GraphAnchorsTask(string[] identifiers, Color color, Vector3 scale)
        {
            var nearAnchorCriteria = new NearAnchorCriteria();

            var watcher = _spatialAnchorManager.Session.CreateWatcher(
                new AnchorLocateCriteria()
            {
                Identifiers = identifiers,
                NearAnchor  = nearAnchorCriteria,
                Strategy    = LocateStrategy.VisualInformation
            });

            var detectedAnchorCount = 0;

            _instructionUIPresenter.UpdateMessage($"アンカーを検知中... {detectedAnchorCount}/{identifiers.Length}");

            var detectedAnchors = await Observable.FromEvent <AnchorLocatedDelegate, AnchorLocatedEventArgs>(
                h => (sender, e) => h.Invoke(e),
                h => _spatialAnchorManager.AnchorLocated += h,
                h => _spatialAnchorManager.AnchorLocated -= h)
                                  .Where(e => e.Status == LocateAnchorStatus.Located)
                                  .Distinct(f => f.Identifier)
                                  .ObserveOnMainThread()
                                  .Do(e =>
            {
                detectedAnchorCount++;
                _instructionUIPresenter.UpdateMessage($"アンカーを検知中... {detectedAnchorCount}/{identifiers.Length}");
                _anchorObjectPresenter.RestoreAnchorObject(e.Anchor, color, scale);
            })
                                  .Take(identifiers.Length)
                                  .ToArray();

            watcher.Stop();
            _instructionUIPresenter.UpdateMessage($"{detectedAnchors.Length}個の全てのアンカーを検知しました!");
            await _instructionUIPresenter.OnTriggerProceed().First();
        }
        private void AdvanceDemo()
        {
            switch (this.currentDemoStep)
            {
            case DemoStep.SaveAnchor:
                if (!this.anchorVisuals.TryGetValue(string.Empty, out AnchorVisual visual))
                {
                    throw new InvalidOperationException("Expected a visual with empty key to be available, but found none.");
                }

                if (visual == null)
                {
                    return;
                }

                if (!this.enoughDataForSaving)
                {
                    return;
                }

                // Hide the back button until we're done
                this.RunOnUiThread(() => this.backButton.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.actionButton.Visibility     = ViewStates.Invisible;
                        this.statusText.Text             = "Saving cloud anchor...";
                    });
                    this.currentDemoStep = DemoStep.SavingAnchor;
                }

                break;

            case DemoStep.StopSession:
                this.cloudAnchorManager.ResetSession(resumeIfRunning: false);
                this.ClearVisuals();

                this.RunOnUiThread(() =>
                {
                    this.statusText.Text   = string.Empty;
                    this.actionButton.Text = "Locate anchor";
                });

                this.currentDemoStep = DemoStep.LocateAnchor;

                break;

            case DemoStep.LocateAnchor:
                // We need to restart the session to find anchors we created.
                this.StartNewSession();

                AnchorLocateCriteria criteria = new AnchorLocateCriteria();
                criteria.SetIdentifiers(new string[] { this.anchorID });

                // Cannot run more than one watcher concurrently
                this.StopWatcher();

                this.anchorsToLocate = 1;
                this.cloudAnchorManager.StartLocating(criteria);

                this.RunOnUiThread(() =>
                {
                    this.actionButton.Visibility = ViewStates.Invisible;
                    this.statusText.Text         = "Look for anchor";
                });

                break;

            case DemoStep.LocateNearbyAnchors:
                if (this.anchorVisuals.Count == 0 || !this.anchorVisuals.ContainsKey(this.anchorID))
                {
                    this.RunOnUiThread(() => this.statusText.Text = "Cannot locate nearby. Previous anchor not yet located.");

                    break;
                }

                AnchorLocateCriteria nearbyLocateCriteria = new AnchorLocateCriteria();
                NearAnchorCriteria   nearAnchorCriteria   = new NearAnchorCriteria
                {
                    DistanceInMeters = 10,
                    SourceAnchor     = this.anchorVisuals[this.anchorID].CloudAnchor
                };
                nearbyLocateCriteria.NearAnchor = nearAnchorCriteria;
                // Cannot run more than one watcher concurrently
                this.StopWatcher();
                this.anchorsToLocate = this.saveCount;
                this.cloudAnchorManager.StartLocating(nearbyLocateCriteria);
                this.RunOnUiThread(() =>
                {
                    this.actionButton.Visibility = ViewStates.Invisible;
                    this.statusText.Text         = "Locating...";
                });

                break;

            case DemoStep.End:
                foreach (AnchorVisual toDeleteVisual in this.anchorVisuals.Values)
                {
                    this.cloudAnchorManager.DeleteAnchorAsync(toDeleteVisual.CloudAnchor);
                }

                this.DestroySession();

                this.RunOnUiThread(() =>
                {
                    this.actionButton.Text     = "Restart";
                    this.statusText.Text       = string.Empty;
                    this.backButton.Visibility = ViewStates.Visible;
                });

                this.currentDemoStep = DemoStep.Restart;

                break;

            case DemoStep.Restart:
                this.StartDemo();
                break;
            }
        }
        private async void advanceDemo()
        {
            switch (currentDemoStep)
            {
            case DemoStep.SaveCloudAnchor:
                AnchorVisual visual = anchorVisuals[""];
                if (visual == null)
                {
                    return;
                }

                if (!enoughDataForSaving)
                {
                    return;
                }

                // Hide the back button until we're done
                RunOnUiThread(() => backButton.Visibility = ViewStates.Gone);

                setupLocalCloudAnchor(visual);

                try
                {
                    await cloudAnchorManager.CreateAnchorAsync(visual.CloudAnchor);
                }
                catch (System.Exception ex)
                {
                    anchorSaveFailed(ex.Message);
                }

                lock (progressLock) {
                    RunOnUiThread(() => {
                        scanProgressText.Visibility = ViewStates.Gone;
                        scanProgressText.Text       = "";
                        actionButton.Visibility     = ViewStates.Invisible;
                        statusText.Text             = "Saving cloud anchor...";
                    });
                    currentDemoStep = DemoStep.SavingCloudAnchor;
                }

                break;

            case DemoStep.CreateSessionForQuery:
                cloudAnchorManager.Stop();
                cloudAnchorManager.Reset();
                clearVisuals();

                RunOnUiThread(() => {
                    statusText.Text   = "";
                    actionButton.Text = "Locate anchor";
                });

                currentDemoStep = DemoStep.LookForAnchor;

                break;

            case DemoStep.LookForAnchor:
                // We need to restart the session to find anchors we created.
                startNewSession();

                AnchorLocateCriteria criteria = new AnchorLocateCriteria();
                criteria.SetIdentifiers(new string[] { anchorID });

                // Cannot run more than one watcher concurrently
                stopWatcher();

                cloudAnchorManager.StartLocating(criteria);

                RunOnUiThread(() =>
                {
                    actionButton.Visibility = ViewStates.Invisible;
                    statusText.Text         = "Look for anchor";
                });

                break;

            case DemoStep.LookForNearbyAnchors:
                if (anchorVisuals.Count == 0 || !anchorVisuals.ContainsKey(anchorID))
                {
                    RunOnUiThread(() => statusText.Text = "Cannot locate nearby. Previous anchor not yet located.");

                    break;
                }

                AnchorLocateCriteria nearbyLocateCriteria = new AnchorLocateCriteria();
                NearAnchorCriteria   nearAnchorCriteria   = new NearAnchorCriteria();
                nearAnchorCriteria.DistanceInMeters = 5;
                nearAnchorCriteria.SourceAnchor     = anchorVisuals[anchorID].CloudAnchor;
                nearbyLocateCriteria.NearAnchor     = nearAnchorCriteria;
                // Cannot run more than one watcher concurrently
                stopWatcher();
                cloudAnchorManager.StartLocating(nearbyLocateCriteria);
                RunOnUiThread(() => {
                    actionButton.Visibility = ViewStates.Invisible;
                    statusText.Text         = "Locating...";
                });

                break;

            case DemoStep.End:
                foreach (AnchorVisual toDeleteVisual in anchorVisuals.Values)
                {
                    var _ = cloudAnchorManager.DeleteAnchorAsync(toDeleteVisual.CloudAnchor);
                }

                destroySession();

                RunOnUiThread(() => {
                    actionButton.Text     = "Restart";
                    statusText.Text       = "";
                    backButton.Visibility = ViewStates.Visible;
                });

                currentDemoStep = DemoStep.Restart;

                break;

            case DemoStep.Restart:
                startDemo();
                break;
            }
        }