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; } }
/// <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"); } }
/// <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"); } }