/// <summary> /// Stop the session and cleanup any anchors created. /// </summary> private void StopAndCleanupSession() { // Clean up the sample scenario, destroying any anchors foreach (GameObject gameObject in m_foundOrCreatedAnchorObjects) { Destroy(gameObject); } m_foundOrCreatedAnchorObjects.Clear(); // Stop the session if (!m_cloudSpatialAnchorManager.IsSessionStarted) { Debug.LogWarning("Cannot stop session; session has not started."); return; } Debug.Log("Stopping session..."); m_cloudSpatialAnchorManager.StopSession(); m_cloudSpatialAnchorManager.Session.Reset(); // Stop the watcher, if it exists if (m_cloudSpatialAnchorWatcher != null) { m_cloudSpatialAnchorWatcher.Stop(); m_cloudSpatialAnchorWatcher = null; } Debug.Log("Session stopped!"); }
public void StopLocating() { CloudSpatialAnchorWatcher watcher = this.cloudSession.GetActiveWatchers().FirstOrDefault(); // Only 1 active watcher at a time is permitted. watcher?.Stop(); }
public async Task StartAzureSession() { startedAsa = true; anchorLocateCriteria = new AnchorLocateCriteria(); CloudManager.SessionUpdated += CloudManager_SessionUpdated; CloudManager.AnchorLocated += CloudManagerOnAnchorLocated; CloudManager.LocateAnchorsCompleted += CloudManager_LocateAnchorsCompleted; CloudManager.LogDebug += CloudManagerOnLogDebug; CloudManager.Error += CloudManager_Error; await CloudManager.CreateSessionAsync(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(ApiURL + "/api/AnchorsAPI"); //.Create(String.Format("http://api.openweathermap.org/data/2.5/weather?id={0}&APPID={1}", CityId, API_KEY)); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string jsonResponse = reader.ReadToEnd(); var result = JsonUtility.FromJson <Response <Anchor> >(jsonResponse); anchorLocateCriteria.Identifiers = result.data.Select(anchor => anchor.identifier).ToArray(); await CloudManager.StartSessionAsync(); if (currentWatcher != null) { currentWatcher.Stop(); currentWatcher = null; } currentWatcher = CreateWatcher(); if (currentWatcher == null) { Debug.Log("Either cloudmanager or session is null, should not be here!"); } }
public void StopLocating() { CloudSpatialAnchorWatcher watcher = this.spatialAnchorsSession.ActiveWatchers.FirstOrDefault(); // Only 1 active watcher at a time is permitted. watcher?.Stop(); watcher?.Dispose(); }
private void StopWatcher() { if (watcher != null) { watcher.Stop(); watcher = null; } }
private void HandleAnchorLocated(object sender, AnchorLocatedEventArgs args) { Debug.Log($"Anchor recognized as a possible Azure anchor"); if (args.Status == LocateAnchorStatus.Located || args.Status == LocateAnchorStatus.AlreadyTracked) { currentCloudAnchor = args.Anchor; AppDispatcher.Instance().Enqueue(() => { Debug.Log($"Azure anchor located successfully"); var indicator = Instantiate(anchorPositionPrefab); #if WINDOWS_UWP || UNITY_WSA indicator.gameObject.CreateNativeAnchor(); if (currentCloudAnchor == null) { return; } Debug.Log("Local anchor position successfully set to Azure anchor position"); indicator.GetComponent <UnityEngine.XR.WSA.WorldAnchor>().SetNativeSpatialAnchorPtr(currentCloudAnchor.LocalAnchor); #elif UNITY_ANDROID || UNITY_IOS Pose anchorPose = Pose.identity; anchorPose = currentCloudAnchor.GetPose(); Debug.Log($"Setting object to anchor pose with position '{anchorPose.position}' and rotation '{anchorPose.rotation}'"); indicator.transform.position = anchorPose.position; indicator.transform.rotation = anchorPose.rotation; // Create a native anchor at the location of the object in question indicator.gameObject.CreateNativeAnchor(); #endif indicator.Init(currentTrackedObject); anchorArrowGuide.SetTargetObject(indicator.transform); activeAnchors.Add(currentTrackedObject.SpatialAnchorId, indicator); // Notify subscribers OnFindAnchorSucceeded?.Invoke(this, EventArgs.Empty); currentWatcher?.Stop(); currentTrackedObject = null; }); } else { Debug.Log($"Attempt to locate Anchor with ID '{args.Identifier}' failed, locate anchor status was not 'Located' but '{args.Status}'"); } StopAzureSession(); }
void OnDestroy() { if (CloudManager != null) { CloudManager.EnableProcessing = false; } if (currentWatcher != null) { currentWatcher.Stop(); currentWatcher = null; } }
void OnDestroy() { if (cloudManager != null && cloudManager.Session != null) { cloudManager.DestroySession(); } if (currentWatcher != null) { currentWatcher.Stop(); currentWatcher = null; } }
public void StopLocating() { var watchers = spatialAnchorsSession.ActiveWatchers; if (watchers.Count == 0) { return; } // Only 1 watcher is at a time is currently permitted. CloudSpatialAnchorWatcher watcher = watchers[0]; watcher.Stop(); }
/// <summary> /// Destroying the attached Behaviour will result in the game or Scene /// receiving OnDestroy. /// </summary> /// <remarks>OnDestroy will only be called on game objects that have previously been active.</remarks> public override void OnDestroy() { if (CloudManager != null) { CloudManager.StopSession(); } if (currentWatcher != null) { currentWatcher.Stop(); currentWatcher = null; } CleanupSpawnedObjects(); // Pass to base for final cleanup base.OnDestroy(); }
/// Destroying the attached Behaviour will result in the game or Scene /// receiving OnDestroy. /// <remarks>OnDestroy will only be called on game objects that have previously been active.</remarks> public /*override*/ void OnDestroy() { if (CloudManager != null) { CloudManager.StopSession(); } if (currentWatcher != null) { currentWatcher.Stop(); currentWatcher = null; } CleanupSpawnedObjects(); // Pass to base for final cleanup // base.OnDestroy(); UnityEngine.XR.WSA.Input.InteractionManager.InteractionSourcePressed -= InteractionManager_InteractionSourcePressed; }
/// <summary> /// オブジェクトの後処理(廃棄)を実施します。 /// </summary> public void OnDestroy() { try { if (cloudManager != null && cloudManager.Session != null) { cloudManager.DestroySession(); } if (currentWatcher != null) { currentWatcher.Stop(); currentWatcher = null; } } catch (Exception e) { Debug.Log(e); throw; } }
private async Task OnDiscoverCoordinatesImplAsync(CancellationToken cancellationToken, string[] idsToLocate = null) { await EnsureInitializedAsync().Unless(cancellationToken); RequestSessionStart(); try { AnchorLocateCriteria anchorLocateCriteria = new AnchorLocateCriteria(); HashSet <string> ids = new HashSet <string>(); if (idsToLocate?.Length > 0) { anchorLocateCriteria.Identifiers = idsToLocate; for (int i = 0; i < idsToLocate.Length; i++) { if (!knownCoordinates.ContainsKey(idsToLocate[i])) { ids.Add(idsToLocate[i]); } } if (ids.Count == 0) { // We know already all of the coordintes return; } } using (CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken)) { // Local handler async void AnchorLocatedHandler(object sender, AnchorLocatedEventArgs args) { if (args.Status == LocateAnchorStatus.Located) { // Switch to UI thread for the rest here await gameThreadSynchronizationContext; GameObject gameObject = CreateGameObjectFrom(args); SpatialAnchorsCoordinate coordinate = new SpatialAnchorsCoordinate(args.Anchor, gameObject); OnNewCoordinate(coordinate.Id, coordinate); lock (ids) { // If we succefully removed one and we are at 0, then stop. // If we never had to locate any, we would always be at 0 but never remove any. if (ids.Remove(args.Identifier) && ids.Count == 0) { // We found all requested, stop cts.Cancel(); } } } } session.AnchorLocated += AnchorLocatedHandler; CloudSpatialAnchorWatcher watcher = session.CreateWatcher(anchorLocateCriteria); try { await cts.Token.AsTask().IgnoreCancellation(); } finally { session.AnchorLocated -= AnchorLocatedHandler; watcher.Stop(); } } } finally { ReleaseSessionStartRequest(); } }
private void StopCurrentWatcher() { currentWatcher?.Stop(); }
public override void MainButtonTap() { if (ignoreMainButtonTaps) { return; } switch (step) { case DemoStep.Start: { UpdateMainStatusTitle("Tap to start Session"); step = DemoStep.CreateAnchor; CreateLocationProvider(); break; } case DemoStep.CreateAnchor: { ignoreMainButtonTaps = true; currentlyPlacingAnchor = true; saveCount = 0; StartSession(); AttachLocationProviderToSession(); // When you tap on the screen, touchesBegan will call createLocalAnchor and create a local ARAnchor. // We will then put that anchor in the anchorVisuals dictionary with a special key and call CreateCloudAnchor when there is enough data for saving. // CreateCloudAnchor will call OnCloudAnchorCreated when its async method returns to move to the next step. UpdateMainStatusTitle("Tap on the screen to create an Anchor ☝️"); break; } case DemoStep.LocateNearbyAnchors: { ignoreMainButtonTaps = true; StopSession(); StartSession(); AttachLocationProviderToSession(); LookForAnchorsNearDevice(); break; } case DemoStep.StopWatcher: { step = DemoStep.StopSession; nearDeviceWatcher?.Stop(); nearDeviceWatcher = null; UpdateMainStatusTitle("Tap to stop Session and return to the main menu"); break; } case DemoStep.StopSession: { StopSession(); locationProvider = null; sensorStatusView.Model = null; MoveToMainMenu(); break; } default: { ShowLogMessage("Demo has somehow entered an invalid state", SubView.ErrorView); break; } } }