/// <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 StopActiveWatchers() { // need to be updated if future SDK supports multiple active watchers if (SessionValid() && cloudSpatialAnchorSession.GetActiveWatchers().Count > 0) { foreach (CloudSpatialAnchorWatcher watcher in cloudSpatialAnchorSession.GetActiveWatchers()) { watcher.Stop(); } } }
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..."); } }); }
/// <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でした。これは期待された動作ではありません。"); } }
private async void LoadAnchorAsync() { AnchorLocateCriteria criteria = new AnchorLocateCriteria(); string anchorId = await storageService.GetAnchorId(); // Local anchor is the same as the last saved one. No need to reload it. if (currentlyLoadingAnchorId == anchorId || loadedAnchor != null && loadedAnchor.Identifier == anchorId) { return; } Debug.Log(DEBUG_FILTER + "we are going to load anchor with id: " + anchorId); currentlyLoadingAnchorId = anchorId; // Stop all other watchers. foreach (var w in cloudSession.GetActiveWatchers()) { w.Stop(); } criteria.Identifiers = new string[] { anchorId }; cloudSession.CreateWatcher(criteria); cloudSession.AnchorLocated += (object sender, AnchorLocatedEventArgs args) => { switch (args.Status) { case LocateAnchorStatus.Located: loadedAnchor = args.Anchor; // Run on UI thread. QueueOnUpdate(() => SpawnOrMoveCurrentAnchoredObject(loadedAnchor)); break; case LocateAnchorStatus.AlreadyTracked: Debug.Log(DEBUG_FILTER + "Anchor already tracked. Identifier: " + args.Identifier); loadedAnchor = args.Anchor; break; case LocateAnchorStatus.NotLocatedAnchorDoesNotExist: Debug.Log(DEBUG_FILTER + "Anchor not located. Identifier: " + args.Identifier); break; case LocateAnchorStatus.NotLocated: Debug.LogError("ASA Error: Anchor not located does not exist. Identifier: " + args.Identifier); break; } }; }
public void LocateAnchor() { // We have saved an anchor, so we will now look for it. if (!String.IsNullOrEmpty(cloudSpatialAnchorId)) { // Create a Watcher to look for the anchor we created. AnchorLocateCriteria criteria = new AnchorLocateCriteria(); criteria.Identifiers = new string[] { cloudSpatialAnchorId }; cloudSpatialAnchorSession.CreateWatcher(criteria); Debug.Log("ASA Info: Watcher created. Number of active watchers: " + cloudSpatialAnchorSession.GetActiveWatchers().Count); cloudSpatialAnchorSession.AnchorLocated += CloudSpatialAnchorSession_AnchorLocated; cloudSpatialAnchorSession.LocateAnchorsCompleted += CloudSpatialAnchorSession_LocateAnchorsCompleted; } //Debug.Log("ASA Info: We will create a new anchor."); //CreateAndSaveSphere(); }
public bool LocateOperationInFlight() { return(SessionValid() && cloudSpatialAnchorSession.GetActiveWatchers().Count > 0); }