예제 #1
0
        /// <summary>
        /// Destroys any existing session and unsubscribes from all events.
        /// </summary>
        public void DestroySession()
        {
            // Warn if already destroyed
            if (session == null)
            {
                Debug.LogWarning($"{nameof(DestroySession)} called but no session exists.");
                return;
            }

            // Make sure the session is stopped
            if (isSessionStarted)
            {
                StopSession();
            }

            // Unsubscribe from session events
            session.OnLogDebug             -= OnLogDebug;
            session.SessionUpdated         -= OnSessionUpdated;
            session.AnchorLocated          -= OnAnchorLocated;
            session.LocateAnchorsCompleted -= OnLocateAnchorsCompleted;
            session.Error -= OnError;

            // Dispose the session
            session.Dispose();

            // Update session variable and raise notification through property setter
            Session = null; // Use property to raise event

            // Reset session status as well
            sessionStatus = null;
        }
예제 #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;
        }
        private void OnDestroy()
        {
            enableProcessing = false;

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

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

            _instance = null;
        }
예제 #6
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
    }
예제 #7
0
        /// <summary>
        /// Destroys any existing session and unsubscribes from all events.
        /// </summary>
        public void DestroySession()
        {
            // Warn if already destroyed
            if (session == null)
            {
                Debug.LogWarning($"{nameof(DestroySession)} called but no session exists.");
                return;
            }

#if UNITY_ANDROID || UNITY_IOS
            // Forget about cached ARFoundation reference points
            pointerToReferencePoints.Clear();

            // Stop getting frames
            arCameraManager.frameReceived -= ArCameraManager_frameReceived;
#endif
            // Make sure the session is stopped
            if (isSessionStarted)
            {
                StopSession();
            }

            // Unsubscribe from session events
            session.OnLogDebug             -= OnLogDebug;
            session.SessionUpdated         -= OnSessionUpdated;
            session.AnchorLocated          -= OnAnchorLocated;
            session.LocateAnchorsCompleted -= OnLocateAnchorsCompleted;
            session.Error -= OnError;

            // Dispose the session
            session.Dispose();

            // Update session variable and raise notification through property setter
            Session = null; // Use property to raise event

            // Reset session status as well
            sessionStatus = null;
        }
예제 #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でした。これは期待された動作ではありません。");
        }
    }