Пример #1
0
        /// <summary>
        /// Stops any existing session but does not destroy it. No error will be
        /// thrown if a session doesn't exist or hasn't been started.
        /// </summary>
        /// In order for the property <see cref="IsSessionStarted"/> and events
        /// like <see cref="SessionStarted"/> and <see cref="SessionStopped"/>
        /// to be tracked correctly, use the <see cref="StartSessionAsync"/> and
        /// <see cref="StopSession"/> methods rather than calling methods
        /// directly on the <see cref="Session"/> instance.
        /// </remarks>
        public void StopSession()
        {
            // Warn if already started
            if (!isSessionStarted)
            {
                Debug.LogWarning($"{nameof(StopSession)} called but no session has been started.");
                return;
            }

            // If no session created, create one
            if (session == null)
            {
                Debug.LogWarning($"{nameof(StopSession)} called but no session has been created.");
                return;
            }

            // Stop the session
            session.Stop();

            // Status is no longer valid
            sessionStatus = null;

            // It's no longer started
            isSessionStarted = false;

            // Notify
            OnSessionStopped();
        }
Пример #2
0
    /// <summary>
    /// Cleans up objects and stops the CloudSpatialAnchorSessions.
    /// </summary>
    public void ResetSession(Action completionRoutine = null)
    {
        Debug.Log("ASA Info: Resetting the session.");

        if (cloudSpatialAnchorSession.GetActiveWatchers().Count > 0)
        {
            Debug.LogError("ASA Error: We are resetting the session with active watchers, which is unexpected.");
        }

        CleanupObjects();

        cloudSpatialAnchorSession.Reset();

        lock (dispatchQueue)
        {
            dispatchQueue.Enqueue(() =>
            {
                if (cloudSpatialAnchorSession != null)
                {
                    cloudSpatialAnchorSession.Stop();
                    cloudSpatialAnchorSession.Dispose();
                    Debug.Log("ASA Info: Session was reset.");
                    completionRoutine?.Invoke();
                }
                else
                {
                    Debug.LogError("ASA Error: cloudSpatialAnchorSession was null, which is unexpected.");
                }
            });
        }
    }
Пример #3
0
    public void LocalizeAnchor()
    {
        DispatcherQueue.Enqueue(() =>
        {
            if (_cloudSpatialAnchorSession == null)
            {
                Log("CloudSpatialAnchorSession was null. Weird.", Color.red);
                return;
            }
            else
            {
                // Initialize session fresh & clean
                CleanupObjects();
                _cloudSpatialAnchorSession.Stop();
                _cloudSpatialAnchorSession.Dispose();
                _cloudSpatialAnchorSession = null;
                InitializeSession();

                // Create a Watcher with anchor ID to locate the anchor that was created before
                AnchorLocateCriteria criteria = new AnchorLocateCriteria
                {
                    Identifiers = new string[] { _currentCloudAnchorId }
                };
                _cloudSpatialAnchorSession.CreateWatcher(criteria);

                Log($"Localizing anchor with {_cloudSpatialAnchorSession.GetActiveWatchers().Count} watchers.\r\nLook around to gather spatial data...");
            }
        });
    }
Пример #4
0
        /// <inheritdoc/>
        protected override void OnManagedDispose()
        {
            base.OnManagedDispose();

            session?.Stop();
            session?.Dispose();
            session = null;
        }
Пример #5
0
        private void ReleaseSessionStartRequest()
        {
            lock (session)
            {
                if (requestsForSessionStart == 1)
                {
                    session.Stop();
                }

                requestsForSessionStart = Math.Max(requestsForSessionStart - 1, 0);
            }
        }
Пример #6
0
        private void OnDestroy()
        {
            enableProcessing = false;

            if (cloudSpatialAnchorSession != null)
            {
                cloudSpatialAnchorSession.Stop();
                cloudSpatialAnchorSession.Dispose();
                cloudSpatialAnchorSession = null;
            }

            if (anchorLocateCriteria != null)
            {
                anchorLocateCriteria = null;
            }

            _instance = null;
        }
Пример #7
0
    /// <summary>
    /// Resets and stops the Azure Spatial Anchor session.
    /// </summary>
    public void StopSession(Action completionRoutine = null)
    {
#if !UNITY_EDITOR
        cloudSpatialAnchorSession.Reset();

        lock (queue)
        {
            queue.Enqueue(() =>
            {
                if (cloudSpatialAnchorSession != null)
                {
                    cloudSpatialAnchorSession.Stop();
                    cloudSpatialAnchorSession.Dispose();
                    completionRoutine?.Invoke();
                }
            });
        }
#endif
    }
Пример #8
0
    /// <summary>
    /// オブジェクトをクリーンアップしてCloudSpatialAnchorセッションを停止する処理
    /// </summary>
    public void ASAResetSession()
    {
        Debug.Log("ASA Info: セッションをリセットします。");

        if (cloudSpatialAnchorSession.GetActiveWatchers().Count > 0)
        {
            Debug.LogError("ASA Error: ActiveなWatcherがあるセッションをリセットしようとしています。これは期待された動作ではありません。");
        }

        currentCloudAnchor = null;

        this.cloudSpatialAnchorSession.Reset();

        if (cloudSpatialAnchorSession != null)
        {
            cloudSpatialAnchorSession.Stop();
            cloudSpatialAnchorSession.Dispose();
            Debug.Log("ASA Info: セッションはリセットされました。");
        }
        else
        {
            Debug.LogError("ASA Error: セッションはNullでした。これは期待された動作ではありません。");
        }
    }
 public void Stop()
 {
     spatialAnchorsSession.Stop();
     StopLocating();
     IsRunning = false;
 }