/// <summary> /// Exports the currently created anchor. /// </summary> private void Export() { UnityEngine.XR.WSA.WorldAnchor anchor = GetComponent <UnityEngine.XR.WSA.WorldAnchor>(); if (anchor == null) { Debug.Log("We should have made an anchor by now..."); return; } string guidString = Guid.NewGuid().ToString(); exportingAnchorName = guidString; // Save the anchor to our local anchor store. if (anchorStore.Save(exportingAnchorName, anchor)) { sharedAnchorInterface = new UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch(); sharedAnchorInterface.AddWorldAnchor(guidString, anchor); UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch.ExportAsync(sharedAnchorInterface, WriteBuffer, ExportComplete); } else { Debug.Log("This anchor didn't work, trying again"); currentState = ImportExportState.InitialAnchorRequired; } }
private void ExportLocalAnchor() { CurrentState = AnchorManagementState.ExportingLocalAnchor; UnityEngine.XR.WSA.WorldAnchor anchor = gameObject.GetComponent <UnityEngine.XR.WSA.WorldAnchor>(); string guidString = Guid.NewGuid().ToString(); exportingAnchorName = guidString; // Save the anchor to our local anchor store. if (anchor != null && anchorStore.Save(exportingAnchorName, anchor)) { Debug.LogFormat("Exporting anchor: {0}", exportingAnchorName); DebugDisplay(string.Format("\nExporting anchor: {0}", exportingAnchorName)); sharedAnchorInterface = new UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch(); sharedAnchorInterface.AddWorldAnchor(guidString, anchor); UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch.ExportAsync(sharedAnchorInterface, WriteBuffer, ExportLocalAnchorComplete); } else { Debug.LogWarning("Anchor Manager: Failed to export anchor, trying again..."); DebugDisplay(string.Format("\nFailed to export anchor, trying again...")); CurrentState = AnchorManagementState.LocalAnchorExportFailed; } }
/// <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.XR.WSA.Sharing.WorldAnchorTransferBatch watb = new UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch(); UnityEngine.XR.WSA.WorldAnchor worldAnchor = objectToAnchor.GetComponent <UnityEngine.XR.WSA.WorldAnchor>(); if (worldAnchor == null) { worldAnchor = objectToAnchor.AddComponent <UnityEngine.XR.WSA.WorldAnchor>(); } exportingAnchorName = Guid.NewGuid().ToString(); Debug.Log("exporting " + exportingAnchorName); watb.AddWorldAnchor(exportingAnchorName, worldAnchor); UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch.ExportAsync(watb, WriteBuffer, ExportComplete); }
/// <summary> /// If we are supposed to create the anchor for export, this is the function to call. /// </summary> public void CreateAnchor() { #if UNITY_EDITOR Debug.LogError("Anchors cannot be created from the Unity editor."); #endif exportingAnchorBytes.Clear(); GenericNetworkTransmitter.Instance.SetData(null); objectToAnchor = UNetAnchorManager.Instance.gameObject; UnityEngine.XR.WSA.WorldAnchor worldAnchor = objectToAnchor.GetComponent <UnityEngine.XR.WSA.WorldAnchor>(); if (worldAnchor == null) { worldAnchor = objectToAnchor.AddComponent <UnityEngine.XR.WSA.WorldAnchor>(); } Debug.Log("Checking for saved anchor: " + AnchorName); if (PlayerPrefs.HasKey(SavedAnchorKey) && AttachToCachedAnchor(PlayerPrefs.GetString(SavedAnchorKey))) { exportingAnchorName = PlayerPrefs.GetString(SavedAnchorKey); Debug.Log("found " + AnchorName + " again"); } else if (PlayerPrefs.HasKey(AnchorName) && AttachToCachedAnchor(AnchorName)) { exportingAnchorName = AnchorName; Debug.Log("_found " + AnchorName + " again"); } else { exportingAnchorName = Guid.NewGuid().ToString(); } UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch watb = new UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch(); Debug.Log("exporting " + exportingAnchorName); watb.AddWorldAnchor(exportingAnchorName, worldAnchor); UnityEngine.XR.WSA.Sharing.WorldAnchorTransferBatch.ExportAsync(watb, WriteBuffer, ExportComplete); SaveAnchor(exportingAnchorName); }