/// <summary> /// If we are supposed to create the anchor for export, this is the function to call. /// </summary> public void CreateAnchor() { objectToAnchor = SharedCollection.Instance.gameObject; UnityEngine.VR.WSA.Sharing.WorldAnchorTransferBatch watb = new UnityEngine.VR.WSA.Sharing.WorldAnchorTransferBatch(); UnityEngine.VR.WSA.WorldAnchor worldAnchor = objectToAnchor.GetComponent <UnityEngine.VR.WSA.WorldAnchor>(); if (worldAnchor == null) { worldAnchor = objectToAnchor.AddComponent <UnityEngine.VR.WSA.WorldAnchor>(); } exportingAnchorName = Guid.NewGuid().ToString(); Debug.Log("exporting " + exportingAnchorName); watb.AddWorldAnchor(exportingAnchorName, worldAnchor); UnityEngine.VR.WSA.Sharing.WorldAnchorTransferBatch.ExportAsync(watb, WriteBuffer, ExportComplete); }
/// <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.VR.WSA.Sharing.SerializationCompletionReason status, UnityEngine.VR.WSA.Sharing.WorldAnchorTransferBatch wat) { if (status == UnityEngine.VR.WSA.Sharing.SerializationCompletionReason.Succeeded && wat.GetAllIds().Length > 0) { Debug.Log("Import complete"); string first = wat.GetAllIds()[0]; Debug.Log("Anchor name: " + first); UnityEngine.VR.WSA.WorldAnchor existingAnchor = objectToAnchor.GetComponent <UnityEngine.VR.WSA.WorldAnchor>(); if (existingAnchor != null) { DestroyImmediate(existingAnchor); } UnityEngine.VR.WSA.WorldAnchor anchor = wat.LockObject(first, objectToAnchor); WorldAnchorManager.Instance.AnchorStore.Save(first, anchor); ImportInProgress = false; AnchorEstablished = true; } else { // if we failed, we can simply try again. gotOne = true; Debug.Log("Import fail"); } }