public void ExportToFile(GameObject gameObjectToExport) { if (exporting) { Debug.LogWarning("Manager is currently exporting, please try again later."); return; } if (gameObjectToExport == null) { Debug.LogError("Invalid GameObject"); return; } var exportAnchor = gameObjectToExport.GetComponent <WorldAnchor>(); if (exportAnchor != null) { if (TransferBatch.anchorCount > 0) { TransferBatch.Dispose(); } TransferBatch.AddWorldAnchor(exportAnchor.name, exportAnchor); WorldAnchorTransferBatch.ExportAsync(TransferBatch, ExportData, ExportComplete); exporting = true; } else { Debug.LogError("Cannot get anchor while exporting"); } }
/// <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; }
/// <summary> /// Called when anchor upload operations complete. /// </summary> private void RoomManagerListener_AnchorUploaded(bool successful, XString failureReason) { if (successful) { string[] anchorIds = currentAnchorTransferBatch.GetAllIds(); for (int i = 0; i < anchorIds.Length; i++) { if (ShowDetailedLogs) { Debug.LogFormat("[SharingWorldAnchorManager] Successfully uploaded anchor \"{0}\".", anchorIds[i]); } if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nSuccessfully uploaded anchor \"{0}\".", anchorIds[i]); } } } else { Debug.LogError("[SharingWorldAnchorManager] Upload failed: " + failureReason); if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nUpload failed: " + failureReason); } } rawAnchorUploadData.Clear(); currentAnchorTransferBatch.Dispose(); currentAnchorTransferBatch = null; isExportingAnchors = false; if (AnchorUploaded != null) { AnchorUploaded(successful); } }
private void exit() { transferBatch?.Dispose(); Debug.Log(" Anchor export stop"); callbackWhenFinished = null; }