public async void CreateAzureAnchor(GameObject theObject) { Debug.Log("\nAnchorModuleScript.CreateAzureAnchor()"); // Notify AnchorFeedbackScript OnCreateAnchorStarted?.Invoke(); // First we create a native XR anchor at the location of the object in question theObject.CreateNativeAnchor(); // Notify AnchorFeedbackScript OnCreateLocalAnchor?.Invoke(); // Then we create a new local cloud anchor CloudSpatialAnchor localCloudAnchor = new CloudSpatialAnchor(); // Now we set the local cloud anchor's position to the native XR anchor's position localCloudAnchor.LocalAnchor = theObject.FindNativeAnchor().GetPointer(); // Check to see if we got the local XR anchor pointer if (localCloudAnchor.LocalAnchor == IntPtr.Zero) { Debug.Log("Didn't get the local anchor..."); return; } else { Debug.Log("Local anchor created"); } // In this sample app we delete the cloud anchor explicitly, but here we show how to set an anchor to expire automatically localCloudAnchor.Expiration = DateTimeOffset.Now.AddDays(7); // Save anchor to cloud while (!cloudManager.IsReadyForCreate) { await Task.Delay(330); float createProgress = cloudManager.SessionStatus.RecommendedForCreateProgress; QueueOnUpdate(new Action(() => Debug.Log($"Move your device to capture more environment data: {createProgress:0%}"))); } bool success; try { Debug.Log("Creating Azure anchor... please wait..."); // Actually save await cloudManager.CreateAnchorAsync(localCloudAnchor); // Store currentCloudAnchor = localCloudAnchor; localCloudAnchor = null; // Success? success = currentCloudAnchor != null; if (success) { Debug.Log($"Azure anchor with ID '{currentCloudAnchor.Identifier}' created successfully"); // Notify AnchorFeedbackScript OnCreateAnchorSucceeded?.Invoke(); // Update the current Azure anchor ID Debug.Log($"Current Azure anchor ID updated to '{currentCloudAnchor.Identifier}'"); currentAzureAnchorID = currentCloudAnchor.Identifier; } else { Debug.Log($"Failed to save cloud anchor with ID '{currentAzureAnchorID}' to Azure"); // Notify AnchorFeedbackScript OnCreateAnchorFailed?.Invoke(); } } catch (Exception ex) { Debug.Log(ex.ToString()); } }
public void CreateAzureAnchor(GameObject theObject) { OnCreateAnchorStarted?.Invoke(); createAnchorCoroutine = StartCoroutine(CreateAzureAnchorIDCorotuine()); //First we create a local anchor at the location of the object in question theObject.AddARAnchor(); //Then we create a new local cloud anchor CloudSpatialAnchor localCloudAnchor = new CloudSpatialAnchor(); //Now we set the local cloud anchor's position to the local anchor's position localCloudAnchor.LocalAnchor = theObject.GetNativeAnchorPointer(); //Check to see if we got the local anchor pointer if (localCloudAnchor.LocalAnchor == IntPtr.Zero) { Debug.Log("Didn't get the local XR anchor pointer..."); return; } // In this sample app we delete the cloud anchor explicitly, but here we show how to set an anchor to expire automatically localCloudAnchor.Expiration = DateTimeOffset.Now.AddDays(7); //Save anchor to cloud Task.Run(async() => { while (!CloudManager.EnoughDataToCreate) { await Task.Delay(330); float createProgress = CloudManager.GetSessionStatusIndicator(AzureSpatialAnchorsDemoWrapper.SessionStatusIndicatorType.RecommendedForCreate); QueueOnUpdate(new Action(() => Debug.Log($"Move your device to capture more environment data: {createProgress:0%}"))); } bool success = false; try { QueueOnUpdate(new Action(() => Debug.Log("Saving..."))); currentCloudAnchor = await CloudManager.StoreAnchorInCloud(localCloudAnchor); //Save the Azure Anchor ID AzureAnchorID = currentCloudAnchor.Identifier; success = currentCloudAnchor != null; localCloudAnchor = null; if (success) { //OnAnchorCreatedSuccessfully?.Invoke(); Debug.Log("Successfully Created Anchor"); } else { Debug.Log("Failed to save, but no exception was thrown."); } } catch (Exception ex) { //OnAnchorCreationfailed?.Invoke(); Debug.Log(ex.ToString()); } }); }
private async void CreateAzureAnchor(AnchorPosition anchorPos) { // change the color of the currentAnchor to inprogress anchorPos.AnchorInProgress(); if (cloudManager.Session == null) { // Creates a new session if one does not exist Debug.Log("\ncloudManager.CreateSessionAsync()"); await cloudManager.CreateSessionAsync(); } // Starts the session if not already started Debug.Log("\ncloudManager.StartSessionAsync()"); await cloudManager.StartSessionAsync(); // Notify AnchorFeedbackScript OnCreateAnchorStarted?.Invoke(); // Create local cloud anchor var localCloudAnchor = new CloudSpatialAnchor(); // Create native XR anchor at the location of the object anchorPos.gameObject.CreateNativeAnchor(); Debug.Log("anchorPosition.gameObject.CreateNativeAnchor()"); // create a cloud anchor at the position of the local anchor localCloudAnchor.LocalAnchor = anchorPos.gameObject.FindNativeAnchor().GetPointer(); Debug.Log("anchorPosition.gameObject.FindNativeAnchor().GetPointer()"); // Check to see if we got the local XR anchor pointer if (localCloudAnchor.LocalAnchor == IntPtr.Zero) { Debug.Log("Didn't get the local anchor..."); return; } else { Debug.Log("Local anchor created"); } // Set expiration (when anchor will be deleted from Azure) localCloudAnchor.Expiration = DateTimeOffset.Now.AddDays(90); // upload cloud anchor to the cloud while (!cloudManager.IsReadyForCreate) { // check with the create progress await Task.Delay(330); var createProgress = cloudManager.SessionStatus.RecommendedForCreateProgress; UnityDispatcher.InvokeOnAppThread(() => Debug.Log($"Move your device to capture more environment data: {createProgress:0%}")); } Debug.Log("cloudManager is ready."); try { // Actually save Debug.Log("await cloudManager.CreateAnchorAsync(localCloudAnchor)"); await cloudManager.CreateAnchorAsync(localCloudAnchor); Debug.Log("Anchor created!"); // Store currentCloudAnchor = localCloudAnchor; localCloudAnchor = null; // Success? var success = currentCloudAnchor != null; if (success) { // update the spaital anchor id of the currentSpatialAnchor Debug.Log($"Azure anchor with ID '{currentCloudAnchor.Identifier}' created successfully"); anchorPos.SpatialAnchorObject.SpatialAnchorId = currentCloudAnchor.Identifier; // Update the current Azure anchor ID Debug.Log($"Current Azure anchor ID updated to '{currentCloudAnchor.Identifier}'"); OnCreateAnchorSucceeded?.Invoke(); } else { Debug.Log($"Failed to save cloud anchor with ID '{currentCloudAnchor.Identifier}' to Azure"); // Notify AnchorFeedbackScript OnCreateAnchorFailed?.Invoke(); } } catch (Exception ex) { Debug.Log(ex.ToString()); } // StopAzureSession(); }