/// <summary> /// Called when a remote anchor has been deserialized. /// </summary> /// <param name="status"></param> /// <param name="anchorBatch"></param> private void ImportComplete(SerializationCompletionReason status, WorldAnchorTransferBatch anchorBatch) { bool successful = status == SerializationCompletionReason.Succeeded; GameObject objectToAnchor = null; if (successful) { if (ShowDetailedLogs) { Debug.LogFormat("[SharingWorldAnchorManager] Successfully imported \"{0}\" anchors.", anchorBatch.anchorCount.ToString()); } if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nSuccessfully imported \"{0}\" anchors.", anchorBatch.anchorCount.ToString()); } string[] anchorNames = anchorBatch.GetAllIds(); for (var i = 0; i < anchorNames.Length; i++) { if (AnchorGameObjectReferenceList.TryGetValue(anchorNames[i], out objectToAnchor)) { AnchorStore.Save(anchorNames[i], anchorBatch.LockObject(anchorNames[i], objectToAnchor)); } else { //TODO: Figure out how to get the GameObject reference from across the network. For now it's best to use unique GameObject names. Debug.LogWarning("[SharingWorldAnchorManager] Unable to import anchor! We don't know which GameObject to anchor!"); if (AnchorDebugText != null) { AnchorDebugText.text += "\nUnable to import anchor! We don\'t know which GameObject to anchor!"; } } } } else { Debug.LogError("[SharingWorldAnchorManager] Import failed!"); if (AnchorDebugText != null) { AnchorDebugText.text += "\nImport failed!"; } } if (AnchorDownloaded != null) { AnchorDownloaded(successful, objectToAnchor); } anchorBatch.Dispose(); rawAnchorDownloadData = null; isImportingAnchors = false; }
// Copy pasted this method from DemoScriptBase to allow specifying gameobject to get cloudnativeanchor from that will be saved. public async Task SaveObjectAnchorToCloudAsyncTask(GameObject go, string recordingId) { // Get the cloud-native anchor behavior CloudNativeAnchor cna = go.GetComponent <CloudNativeAnchor>(); // If the cloud portion of the anchor hasn't been created yet, create it if (cna.CloudAnchor == null) { cna.NativeToCloud(); } // Get the cloud portion of the anchor CloudSpatialAnchor cloudAnchor = cna.CloudAnchor; while (!CloudManager.IsReadyForCreate) { await Task.Delay(330); float createProgress = CloudManager.SessionStatus.RecommendedForCreateProgress; Debug.Log($"Move your device to capture more environment data: {createProgress:0%}\n"); } bool success = false; try { // Actually save await CloudManager.CreateAnchorAsync(cloudAnchor); // Success? success = cloudAnchor != null; if (success && !isErrorActive) { anchorStore.Save(cloudAnchor.Identifier, recordingId); await OnSaveCloudAnchorSuccessfulAsync(); } else { OnSaveCloudAnchorFailed(new Exception("Failed to save, but no exception was thrown.")); } } catch (Exception ex) { OnSaveCloudAnchorFailed(ex); } }