/// <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; }
/// <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."); } }); } }
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..."); } }); }
/// <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; }
/// <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 }
/// <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; }
/// <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でした。これは期待された動作ではありません。"); } }