/// <summary> /// Called when a remote anchor has been deserialized /// </summary> /// <param name="status"></param> /// <param name="wat"></param> private void ImportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason status, UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch wat) { if (status == UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded) { if (SharingStage.Instance.ShowDetailedLogs) { Debug.Log("Import complete"); } if (wat.GetAllIds().Length > 0) { string first = wat.GetAllIds()[0]; if (SharingStage.Instance.ShowDetailedLogs) { Debug.Log("Anchor name: " + first); } UnityEngine.XR.WSA.WorldAnchor anchor = wat.LockObject(first, gameObject); anchorStore.Save(first, anchor); } AnchorLoadComplete(); } else { Debug.LogError("Import failed"); currentState = ImportExportState.DataReady; } }
/// <summary> /// Called when a remote anchor has been deserialized /// </summary> /// <param name="status">Tracks if the import worked</param> /// <param name="wat">The WorldAnchorTransferBatch that has the anchor information.</param> private void ImportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason status, UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch wat) { if (status == UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded && wat.GetAllIds().Length > 0) { Debug.Log("Import complete"); string first = wat.GetAllIds()[0]; Debug.Log("Anchor name: " + first); UnityEngine.XR.WSA.WorldAnchor existingAnchor = objectToAnchor.GetComponent <UnityEngine.XR.WSA.WorldAnchor>(); if (existingAnchor != null) { DestroyImmediate(existingAnchor); } UnityEngine.XR.WSA.WorldAnchor anchor = wat.LockObject(first, objectToAnchor); anchor.OnTrackingChanged += Anchor_OnTrackingChanged; Anchor_OnTrackingChanged(anchor, anchor.isLocated); ImportInProgress = false; } else { // if we failed, we can simply try again. gotOne = true; Debug.Log("Import fail"); } }
private void AnchorImportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason status, UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch anchorBatch) { if (status == UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded) { if (anchorBatch.GetAllIds().Length > 0) { // HACK: Specify Anchor ID //string anchorEntry = anchorBatch.GetAllIds(); string anchorEntry = storedAnchorString.GetString(); Debug.LogFormat("Anchor Manager: Sucessfully Attached Remote Anchor: {0}", anchorEntry); DebugDisplay(string.Format("\nSucessfully Attached Remote Anchor: {0}", anchorEntry)); UnityEngine.XR.WSA.WorldAnchor anchor = anchorBatch.LockObject(anchorEntry, gameObject); anchorStore.Save(anchorEntry, anchor); remoteAnchorName = string.Empty; } IsAnchorConfigured = true; IsLocalAnchor = false; CurrentState = AnchorManagementState.RemoteAnchorAttached; } else { IsAnchorConfigured = false; Debug.LogError("Remote Anchor Attach Failed"); DebugDisplay("\nRemote Anchor Attach Failed"); CurrentState = AnchorManagementState.RemoteAnchorDataReady; } }
private void ExportLocalAnchorComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason status) { // TODO: ENFORCE Anchor Size LIMIT DebugDisplay(string.Format("\nExport Anchor Size {0} - {1}/{2}: {3}", exportingAnchorName, exportingAnchorBytes.Count, MinTrustworthySerializedAnchorDataSize, exportingAnchorBytes.Count > MinTrustworthySerializedAnchorDataSize)); if (status == UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > MinTrustworthySerializedAnchorDataSize) { Debug.LogFormat("Uploading anchor: {0}", exportingAnchorName); DebugDisplay(string.Format("\nUploading anchor: {0}", exportingAnchorName)); roomManager.UploadAnchor( currentRoom, new XString(exportingAnchorName), exportingAnchorBytes.ToArray(), exportingAnchorBytes.Count); } else { Debug.LogWarning("Anchor Manager: Failed to upload anchor, trying again..."); DebugDisplay(string.Format("\nFailed to upload anchor, trying again...")); CurrentState = AnchorManagementState.CreateLocalAnchor; } }
/// <summary> /// Called when a remote anchor has been deserialized. /// </summary> /// <param name="status"></param> /// <param name="anchorBatch"></param> private void ImportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason status, UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch anchorBatch) { bool successful = status == UnityEngine.XR.WSA.Sharing.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 by the WorldAnchorTransferBatch when anchor exporting is complete. /// </summary> /// <param name="status">Serialization Status.</param> private void ExportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason status) { if (status == UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded && rawAnchorUploadData.Count > MinTrustworthySerializedAnchorDataSize) { if (ShowDetailedLogs) { Debug.LogFormat("[SharingWorldAnchorManager] Exporting {0} anchors with {1} bytes.", currentAnchorTransferBatch.anchorCount.ToString(), rawAnchorUploadData.ToArray().Length.ToString()); } if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nExporting {0} anchors with {1} bytes.", currentAnchorTransferBatch.anchorCount.ToString(), rawAnchorUploadData.ToArray().Length.ToString()); } string[] anchorNames = currentAnchorTransferBatch.GetAllIds(); for (var i = 0; i < anchorNames.Length; i++) { SharingStage.Instance.Manager.GetRoomManager().UploadAnchor( SharingStage.Instance.CurrentRoom, new XString(anchorNames[i]), rawAnchorUploadData.ToArray(), rawAnchorUploadData.Count); } } else { Debug.LogWarning("[SharingWorldAnchorManager] Failed to upload anchor!"); if (AnchorDebugText != null) { AnchorDebugText.text += "\nFailed to upload anchor!"; } if (rawAnchorUploadData.Count < MinTrustworthySerializedAnchorDataSize) { Debug.LogWarning("[SharingWorldAnchorManager] Anchor data was not valid. Try creating the anchor again."); if (AnchorDebugText != null) { AnchorDebugText.text += "\nAnchor data was not valid. Try creating the anchor again."; } } } }
/// <summary> /// Called by the WorldAnchorTransferBatch when anchor exporting is complete. /// </summary> /// <param name="status"></param> public void ExportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason status) { if (status == UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > minTrustworthySerializedAnchorDataSize) { Debug.Log("Uploading anchor: " + exportingAnchorName); roomManager.UploadAnchor( currentRoom, new XString(exportingAnchorName), exportingAnchorBytes.ToArray(), exportingAnchorBytes.Count); } else { Debug.Log("This anchor didn't work, trying again"); currentState = ImportExportState.InitialAnchorRequired; } }
/// <summary> /// Called when serializing an anchor is complete. /// </summary> /// <param name="status">If the serialization succeeded.</param> private void ExportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason status) { if (status == UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > minTrustworthySerializedAnchorDataSize) { AnchorName = exportingAnchorName; anchorData = exportingAnchorBytes.ToArray(); GenericNetworkTransmitter.Instance.SetData(anchorData); createdAnchor = true; Debug.Log("Anchor ready"); GenericNetworkTransmitter.Instance.ConfigureAsServer(); AnchorEstablished = true; } else { CreateAnchor(); } }
/// <summary> /// Called when a remote anchor has been deserialized /// </summary> /// <param name="status"></param> /// <param name="wat"></param> private void ImportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason status, UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch wat) { if (status == UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded && wat.GetAllIds().Length > 0) { Debug.Log("Import complete"); string first = wat.GetAllIds()[0]; Debug.Log("Anchor name: " + first); UnityEngine.XR.WSA.WorldAnchor anchor = wat.LockObject(first, gameObject); anchorStore.Save(first, anchor); currentState = ImportExportState.Ready; } else { Debug.Log("Import fail"); currentState = ImportExportState.DataReady; } }
private void OnImportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason completionReason, UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch deserializedTransferBatch) { if (completionReason != UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded) { LogAsync("Failed to import: " + completionReason.ToString()); return; } string[] ids = deserializedTransferBatch.GetAllIds(); if (ids.Length > 0) { if (m_PointOfReference) { DestroyImmediate(m_PointOfReference); } m_PointOfReferenceCube.transform.position = Vector3.zero; m_PointOfReferenceCube.transform.localScale = Vector3.one * 0.1f; m_PointOfReference = deserializedTransferBatch.LockObject(ids[0], m_PointOfReferenceCube); if (StatusText.Instance) { StatusText.Instance.SetText("Anchor Created"); } Debug.Log("Anchor Created"); if (store != null) { store.Delete(PointOfReferenceID); } StartCoroutine(SaveAnchor()); if (StatusText.Instance) { StatusText.Instance.SetText("Anchor Saved to Store"); } Debug.Log("Anchor Saved to Store"); } }
/// <summary> /// Called by the WorldAnchorTransferBatch when anchor exporting is complete. /// </summary> /// <param name="status"></param> private void ExportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason status) { if (status == UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > MinTrustworthySerializedAnchorDataSize) { if (SharingStage.Instance.ShowDetailedLogs) { Debug.Log("Uploading anchor: " + exportingAnchorName); } roomManager.UploadAnchor( currentRoom, new XString(exportingAnchorName), exportingAnchorBytes.ToArray(), exportingAnchorBytes.Count); } else { Debug.LogWarning("Failed to export anchor, trying again..."); currentState = ImportExportState.InitialAnchorRequired; } }
/// <summary> /// Called when serializing an anchor is complete. /// </summary> /// <param name="status">If the serialization succeeded.</param> private void ExportComplete(UnityEngine.XR.WSA.Sharing.SerializationCompletionReason status) { if (status == UnityEngine.XR.WSA.Sharing.SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > minTrustworthySerializedAnchorDataSize) { AnchorName = exportingAnchorName; anchorData = exportingAnchorBytes.ToArray(); GenericNetworkTransmitter.Instance.SetData(anchorData); createdAnchor = true; Debug.Log("Anchor ready " + exportingAnchorBytes.Count); GenericNetworkTransmitter.Instance.ConfigureAsServer(); AnchorEstablished = true; PlayerController.Instance.CmdSetAnchorName(exportingAnchorName); } else { Debug.Log("Create anchor failed " + status + " " + exportingAnchorBytes.Count); exportingAnchorBytes.Clear(); objectToAnchor = UNetAnchorManager.Instance.gameObject; DestroyImmediate(objectToAnchor.GetComponent <UnityEngine.XR.WSA.WorldAnchor>()); CreateAnchor(); } }