/// <summary> /// WorldAnchorをシリアライズしてストレージに保存します。 /// </summary> public void ExportAnchor() { string guidString = Guid.NewGuid().ToString(); m_exportingAnchorID = guidString; // ローカルのストアにアンカーを保存 var worldAnchor = m_gameObject.GetComponent <WorldAnchor>(); if (worldAnchor != null && m_anchorStore.Save(m_exportingAnchorID, worldAnchor)) { // 保存成功時 Debug.Log("Anchor Manager: Exporting anchor " + m_exportingAnchorID); // WorldAnchorTransferBatchにアンカーのシリアライズを委譲 sharedAnchorInterface = new WorldAnchorTransferBatch(); sharedAnchorInterface.AddWorldAnchor(guidString, worldAnchor); WorldAnchorTransferBatch.ExportAsync(sharedAnchorInterface, WriteBuffer, ExportComplete); } else { Debug.LogWarning("Anchor Manager: Failed to export anchor, trying again..."); } }
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"); } }
// Sets the origin and creates a world anchor private static WorldAnchor CreateWorldAnchor(Vector3 position, Quaternion rotation) { // Create world anchor GameObject anchorObject = new GameObject("Origin"); anchorObject.transform.position = position; anchorObject.transform.rotation = rotation; WorldAnchor worldAnchor = anchorObject.AddComponent <WorldAnchor>(); #if !UNITY_EDITOR if (MixedRealityDisplay.currentDisplay.shareOrigin) { // Share the world anchor WorldAnchorTransferBatch transferBatch = new WorldAnchorTransferBatch(); transferBatch.AddWorldAnchor(MixedRealityDisplay.currentDisplayConfig.id, worldAnchor); WorldAnchorTransferBatch.ExportAsync(transferBatch, (byte[] data) => { RPCManager.CallOnMaster(UniSAConfig.current, NodeConfig.current.id, "ShareOriginData", Encoding.ASCII.GetString(data)); }, (SerializationCompletionReason completionReason) => { RPCManager.CallOnMaster(UniSAConfig.current, "ShareOriginComplete", NodeConfig.current.id, completionReason == SerializationCompletionReason.Succeeded); }); } #endif return(worldAnchor); }
/// <summary> /// If we are supposed to create the anchor for export, this is the function to call. /// </summary> public void CreateAnchor() { exportingAnchorBytes.Clear(); GenericNetworkTransmitter.Instance.SetData(null); objectToAnchor = SharedCollection.Instance.gameObject; if (PlayerPrefs.HasKey(SavedAnchorKey) && AttachToCachedAnchor(PlayerPrefs.GetString(SavedAnchorKey))) { exportingAnchorName = PlayerPrefs.GetString(SavedAnchorKey); Debug.Log("found " + AnchorName + " again"); } else { exportingAnchorName = Guid.NewGuid().ToString(); } WorldAnchorTransferBatch watb = new WorldAnchorTransferBatch(); WorldAnchor worldAnchor = objectToAnchor.GetComponent <WorldAnchor>(); if (worldAnchor == null) { worldAnchor = objectToAnchor.AddComponent <WorldAnchor>(); } Debug.Log("exporting " + exportingAnchorName); watb.AddWorldAnchor(exportingAnchorName, worldAnchor); WorldAnchorTransferBatch.ExportAsync(watb, WriteBuffer, ExportComplete); }
private void ExportWorldAnchor() { WorldAnchorTransferBatch transferBatch = new WorldAnchorTransferBatch(); transferBatch.AddWorldAnchor("GameRootAnchor", WorldCenter.GetComponent <WorldAnchor>()); WorldAnchorTransferBatch.ExportAsync(transferBatch, OnExportDataAvailable, OnExportComplete); }
/// <summary> /// Exports the currently created anchor. /// </summary> private void Export() { string guidString = Guid.NewGuid().ToString(); exportingAnchorName = guidString; // Save the anchor to our local anchor store. if (thisAnchor != null && anchorStore.Save(exportingAnchorName, thisAnchor)) { if (SharingStage.Instance.ShowDetailedLogs) { Debug.Log("Anchor Manager: Exporting anchor " + exportingAnchorName); } if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nExporting anchor {0}", exportingAnchorName); } sharedAnchorInterface = new WorldAnchorTransferBatch(); sharedAnchorInterface.AddWorldAnchor(guidString, thisAnchor); WorldAnchorTransferBatch.ExportAsync(sharedAnchorInterface, WriteBuffer, ExportComplete); } else { Debug.LogWarning("Anchor Manager: Failed to export anchor, trying again..."); if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nFailed to export anchor, trying again..."); } currentState = ImportExportState.InitialAnchorRequired; } }
/// <summary> /// Exports the currently created anchor. /// </summary> void Export() { WorldAnchor anchor = GetComponent <WorldAnchor>(); if (anchor == null) { DisplayUI.Instance.AppendText("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 WorldAnchorTransferBatch(); sharedAnchorInterface.AddWorldAnchor(guidString, anchor); WorldAnchorTransferBatch.ExportAsync(sharedAnchorInterface, WriteBuffer, ExportComplete); } else { DisplayUI.Instance.AppendText("This anchor didn't work, trying again"); currentState = ImportExportState.InitialAnchorRequired; } }
void TransferAnchor(string anchorName, WorldAnchor worldAnchor) { var batch = new WorldAnchorTransferBatch(); batch.AddWorldAnchor(anchorName, worldAnchor); WorldAnchorTransferBatch.ExportAsync(batch, OnDataAvailable, OnDataExported); }
/// <summary> /// Exports the anchor on the ObjectToAnchor. /// </summary> private void ExportAnchor() { WorldAnchorTransferBatch watb = new WorldAnchorTransferBatch(); WorldAnchor worldAnchor = ObjectToAnchor.GetComponent <WorldAnchor>(); watb.AddWorldAnchor(exportingAnchorName, worldAnchor); WorldAnchorTransferBatch.ExportAsync(watb, WriteBuffer, ExportComplete); }
public WorldAnchorExport(WorldAnchorTransferBatch transferBatch, UnityAction <List <byte> > callbackWhenFinished) { this.transferBatch = transferBatch; toExport = new List <byte>(); this.callbackWhenFinished = callbackWhenFinished; WorldAnchorTransferBatch.ExportAsync(transferBatch, onExportDataAvailable, onExportCompleted); }
private void ExportWorldAnchor(string id, WorldAnchor anchor) { HololensConfigController.Instance.logMessage("Starting world anchor export 2..."); exportedAnchorStoreData.Clear(); WorldAnchorTransferBatch transferBatch = new WorldAnchorTransferBatch(); transferBatch.AddWorldAnchor(id, anchor); WorldAnchorTransferBatch.ExportAsync(transferBatch, OnExportDataAvailable, OnExportComplete); }
internal void UploadWorldAnchor(WorldAnchor wa, WorldAnchorTransferBatch.SerializationDataAvailableDelegate OnExportDataAvailable, WorldAnchorTransferBatch.SerializationCompleteDelegate OnExportComplete) { // Serialise the world anchor and then send the byte array // to the server.. WorldAnchorTransferBatch transferBatch = new WorldAnchorTransferBatch(); transferBatch.AddWorldAnchor("GameRootAnchor", wa); WorldAnchorTransferBatch.ExportAsync(transferBatch, OnExportDataAvailable, OnExportComplete); }
IEnumerator ExportFloorAnchor(WorldAnchor worldAnchor) { while (!worldAnchor.isLocated) { yield return(new WaitForSeconds(0.5f)); } WorldAnchorTransferBatch transferBatch = new WorldAnchorTransferBatch(); transferBatch.AddWorldAnchor(gameObject.name, worldAnchor); WorldAnchorTransferBatch.ExportAsync(transferBatch, OnExportDataAvailable, OnExportComplete); }
private void Save(string filename, string anchorName, WorldAnchor anchor) { exportFilename = filename; exportAnchorName = anchorName; exportedAnchor = anchor; ms = new MemoryStream(); WorldAnchorTransferBatch transferBatch = new WorldAnchorTransferBatch(); transferBatch.AddWorldAnchor(exportAnchorName, exportedAnchor); WorldAnchorTransferBatch.ExportAsync(transferBatch, OnExportDataAvailable, OnExportComplete); }
public bool TrySharingAnchor(String anchorId, GameObject gameObject) { if (HolographicSettings.IsDisplayOpaque) { Debug.LogFormat("[NetworkAnchorManager] Ignoring share anchor request, as this device doesn't support anchoring. (anchor id: {0})", anchorId); return(false); } if (AnchorSource.AnchorId == anchorId) { Debug.LogFormat("[NetworkAnchorManager] Ignoring share anchor request, as anchor is already being shared. (anchor id: {0})", anchorId); return(false); } if (LastReceivedAnchor != null && LastReceivedAnchor.AnchorId == anchorId) { Debug.LogFormat("[NetworkAnchorManager] Ignoring share anchor request, as anchor was just received. (anchor id: {0})", anchorId); return(false); } WorldAnchor worldAnchor = gameObject.GetComponent <WorldAnchor>(); if (worldAnchor == null) { Debug.LogErrorFormat("[NetworkAnchorManager] Unable to acquire anchor ownership. Game object is missing an anchor. (anchor id: {0})", anchorId); return(false); } Debug.LogFormat("[NetworkAnchorManager] Attempting to acquire anchor ownership and share anchor with other players. (new anchor id: {0}) {1} {2}", anchorId, AnchorSource.ToString(), DebugInfo()); // The last received anchor will no longer be relevant since we're taking ownership LastReceivedAnchor = null; // Stop all pending work on the anchor transmitter anchorTransmitter.StopAll(); // Export binary data List <byte> buffer = new List <byte>(); WorldAnchorTransferBatch batch = new WorldAnchorTransferBatch(); batch.AddWorldAnchor(anchorId, worldAnchor); WorldAnchorTransferBatch.ExportAsync( batch, (byte[] data) => { buffer.AddRange(data); }, (SerializationCompletionReason status) => { ExportAnchorDataComplete(status, buffer.ToArray(), anchorId, gameObject); }); return(true); }
static async Task <byte[]> ExportWorldAnchorForGameObjectAsync( GameObject gameObject) { byte[] bits = null; var worldAnchor = gameObject.GetComponent <WorldAnchor>(); await UpdateCheckPredicate.WaitForPredicateAsync( gameObject, () => worldAnchor.isLocated); using (var worldAnchorBatch = new WorldAnchorTransferBatch()) { worldAnchorBatch.AddWorldAnchor("anchor", worldAnchor); var completion = new TaskCompletionSource <bool>(); using (var memoryStream = new MemoryStream()) { Debug.Log("Exporting world anchor..."); WorldAnchorTransferBatch.ExportAsync( worldAnchorBatch, data => { memoryStream.Write(data, 0, data.Length); }, reason => { Debug.Log("Export completed - succeeded? " + (reason == SerializationCompletionReason.Succeeded)); if (reason != SerializationCompletionReason.Succeeded) { bits = null; } else { bits = memoryStream.ToArray(); } completion.SetResult(bits != null); } ); await completion.Task; } } return(bits); }
public void SaveAllColumnAnchorsToDisk(WorldAnchor[] columnAnchors) { OnSaveAnchorsToDiskStarted(); WorldAnchorTransferBatch batch = new WorldAnchorTransferBatch(); foreach (WorldAnchor anchor in columnAnchors) { batch.AddWorldAnchor(anchor.gameObject.name, anchor); } ProgressIndicator.Instance.SetProgress(0.10f); ProgressIndicator.Instance.SetMessage("Serializing World Anchors to bytes..."); WorldAnchorTransferBatch.ExportAsync(batch, OnExportDataAvailable, OnExportCompleteColumn); }
/// <summary> /// Exports the anchor on the objectToAnchor. /// </summary> private void ExportAnchor() { WorldAnchorTransferBatch watb = new WorldAnchorTransferBatch(); WorldAnchor worldAnchor = objectToAnchor.GetComponent <WorldAnchor>(); watb.AddWorldAnchor(exportingAnchorName, worldAnchor); WorldAnchorTransferBatch.ExportAsync(watb, WriteBuffer, ExportComplete); // If we started the observer to find a good anchor position, then we need to // stop the observer. if (StartedObserver) { spatialMapping.StopObserver(); StartedObserver = false; } }
/// <summary> /// Exports the currently created anchor. /// </summary> private void Export() { WorldAnchor anchor = GetComponent <WorldAnchor>(); if (anchor == null) { Debug.Log("We should have made an anchor by now..."); return; } exportingAnchorName = "robot-placement"; sharedAnchorInterface = new WorldAnchorTransferBatch(); sharedAnchorInterface.AddWorldAnchor(exportingAnchorName, anchor); WorldAnchorTransferBatch.ExportAsync(sharedAnchorInterface, WriteBuffer, OnExportComplete); }
/// <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; WorldAnchorTransferBatch watb = new WorldAnchorTransferBatch(); WorldAnchor worldAnchor = objectToAnchor.GetComponent <WorldAnchor>(); if (worldAnchor == null) { worldAnchor = objectToAnchor.AddComponent <WorldAnchor>(); } exportingAnchorName = Guid.NewGuid().ToString(); Debug.Log("exporting " + exportingAnchorName); watb.AddWorldAnchor(exportingAnchorName, worldAnchor); 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 (PlayerPrefs.HasKey(SavedAnchorKey) && AttachToCachedAnchor(PlayerPrefs.GetString(SavedAnchorKey))) { AnchorName = PlayerPrefs.GetString(SavedAnchorKey); Debug.Log("found " + AnchorName + " again"); } else { Debug.Log("Could not find cached anchor."); AnchorName = Guid.NewGuid().ToString(); } exportingAnchorBytes.Clear(); AnchorNetworkTransmitter.Instance.SetData(null); WorldAnchor worldAnchor = objectToAnchor.GetComponent <WorldAnchor>(); if (worldAnchor == null) { Debug.Log("Adding a new anchor."); worldAnchor = objectToAnchor.AddComponent <WorldAnchor>(); } if (!AnchorEstablished) { if (worldAnchor.isLocated) { Debug.Log("World anchor already located."); Debug.Log("Saving Anchor."); AnchorEstablished = true; SaveAnchor(worldAnchor); } else { worldAnchor.OnTrackingChanged += Anchor_OnTrackingChanged; Anchor_OnTrackingChanged(worldAnchor, worldAnchor.isLocated); } } Debug.Log("exporting " + AnchorName); WorldAnchorTransferBatch watb = new WorldAnchorTransferBatch(); watb.AddWorldAnchor(AnchorName, worldAnchor); WorldAnchorTransferBatch.ExportAsync(watb, WriteBuffer, ExportComplete); }
public override void SaveWorldAnchor(GameObject gameObj, AnchorSavedDelegate anchorSaved) { if (isDisplayOpaque) { base.SaveWorldAnchor(gameObj, anchorSaved); return; } WorldAnchor anchor = gameObj != null?gameObj.GetComponent <WorldAnchor>() : null; if (anchor == null) { anchor = gameObj != null?gameObj.GetComponentInParent <WorldAnchor>() : null; } if (anchor == null) { if (anchorSaved != null) { anchorSaved(string.Empty, "AnchorNotFound"); } return; } // init buffer InitMemBuffer(MemBufferLength); string anchorId = anchor.gameObject.name; WorldAnchorTransferBatch transferBatch = new WorldAnchorTransferBatch(); transferBatch.AddWorldAnchor(anchorId, anchor); WorldAnchorTransferBatch.ExportAsync(transferBatch, (data) => { WriteMemBuffer(data); }, (result) => { if (anchorSaved != null) { anchorSaved(result == SerializationCompletionReason.Succeeded ? anchorId : string.Empty, result == SerializationCompletionReason.Succeeded ? string.Empty : result.ToString()); } }); }
void ExportWorldAnchor() { string guidString = Guid.NewGuid().ToString(); exportingAnchorName = guidString; // Save the anchor to our local anchor store. if (SharingStage.Instance.ShowDetailedLogs) { Debug.Log("Anchor Manager: Exporting anchor " + exportingAnchorName); } #if UNITY_WSA && !UNITY_EDITOR worldAnchorTransferBatch = new WorldAnchorTransferBatch(); worldAnchorTransferBatch.AddWorldAnchor(guidString, worldAnchor); WorldAnchorTransferBatch.ExportAsync(worldAnchorTransferBatch, WriteBuffer, ExportComplete); #endif // UNITY_WSA }
public void TransferAnchor(WorldAnchor worldAnchor) { if (worldAnchor == null) { return; } exportingAnchorName = worldAnchor.gameObject.name; //Guid.NewGuid().ToString(); _anchorStore.Delete(exportingAnchorName); if (_anchorStore.Save(exportingAnchorName, worldAnchor)) { exportingAnchorBytes.Clear(); var batch = new WorldAnchorTransferBatch(); batch.AddWorldAnchor(exportingAnchorName, worldAnchor); WorldAnchorTransferBatch.ExportAsync(batch, OnDataAvailable, OnDataExported); } }
protected override void Update() { if (AnchorStore == null || SharingStage.Instance == null || SharingStage.Instance.CurrentRoom == null || !canUpdate) { return; } if (LocalAnchorOperations.Count > 0) { if (!isExportingAnchors && !isImportingAnchors) { DoAnchorOperation(LocalAnchorOperations.Dequeue()); } } else { if (shouldImportAnchors && !isImportingAnchors && !isExportingAnchors) { if (AnchorDebugText != null) { AnchorDebugText.text += "\nStarting Anchor Download..."; } isImportingAnchors = true; shouldImportAnchors = false; WorldAnchorTransferBatch.ImportAsync(rawAnchorDownloadData, ImportComplete); } if (shouldExportAnchors && !isExportingAnchors && !isImportingAnchors) { if (AnchorDebugText != null) { AnchorDebugText.text += "\nStarting Anchor Upload..."; } isExportingAnchors = true; shouldExportAnchors = false; WorldAnchorTransferBatch.ExportAsync(currentAnchorTransferBatch, WriteBuffer, ExportComplete); } } }
private void ProcessNetworkAnchors() { // Send New Anchors if (isNewAnchor && worldAnchor != null) { isNewAnchor = false; Debug.LogError("AnchorControl: ProcessNetworkAnchors"); WorldAnchorTransferBatch watb = new WorldAnchorTransferBatch(); if (watb.AddWorldAnchor(ClientId, worldAnchor)) { WorldAnchorTransferBatch.ExportAsync(watb, WriteBuffer, AnchorExportHandler); } else { Debug.LogError("WorldAnchorTransferBatch-Add Anchor Error"); } } }
/// <summary> /// Exports a world anchor over MQTT /// Attaches an anchor, if there is no attached /// </summary> public void exportAnchorToWorldAnchorExportManager() { if (Application.isEditor) { //WA does not work in editor mode return; } //we make sure there is an anchor attached attachWorldAnchorNow(); WorldAnchorTransferBatch transferBatch = new WorldAnchorTransferBatch(); transferBatch.AddWorldAnchor(gameObject.name, GetComponent <WorldAnchor>()); //reset export list toExport = null; WorldAnchorTransferBatch.ExportAsync(transferBatch, onExportDataAvailable, onExportCompleted); }
/// <summary> /// Exports the currently created anchor. /// </summary> private void Export() { var anchor = GetComponent <WorldAnchor>(); string guidString = Guid.NewGuid().ToString(); exportingAnchorName = guidString; // Save the anchor to our local anchor store. if (anchor != null && anchorStore.Save(exportingAnchorName, anchor)) { sharedAnchorInterface = new WorldAnchorTransferBatch(); sharedAnchorInterface.AddWorldAnchor(guidString, anchor); WorldAnchorTransferBatch.ExportAsync(sharedAnchorInterface, WriteBuffer, ExportComplete); } else { Debug.LogWarning("Failed to export anchor, trying again..."); currentState = ImportExportState.InitialAnchorRequired; } }
private void StartExportingWorldAnchor() { Debug.Log("StartExportingWorldAnchor"); if (worldAnchor == null) { worldAnchor = gameObject.GetComponent <WorldAnchor>(); } if (worldAnchor == null) { return; } worldAnchorBuffer.Clear(); WorldAnchorTransferBatch transferBatch = new WorldAnchorTransferBatch(); transferBatch.AddWorldAnchor(gameObject.name, worldAnchor); WorldAnchorTransferBatch.ExportAsync(transferBatch, OnExportDataAvailable, OnExportComplete); }
/// <summary> ///导出锚点数据 /// </summary> /// <param name="objectToUploadAnchor"></param> /// <param name="anchorName"></param> public void ExportAnchorData(GameObject objectToUploadAnchor, string anchorName) { exportAnchorName = anchorName; #if !UNITY_EDITOR && UNITY_WSA WorldAnchorTransferBatch watb = new WorldAnchorTransferBatch(); WorldAnchor worldAnchor = objectToUploadAnchor.GetComponent <WorldAnchor>(); if (worldAnchor == null) { Debug.Log("物体无锚点,无法导出!!!"); } else { Debug.Log("导出锚点: " + anchorName); MYDialog.Instance.Write("导出锚点: " + anchorName); watb.AddWorldAnchor(anchorName, worldAnchor); WorldAnchorTransferBatch.ExportAsync(watb, WriteBuffer, ExportComplete); } #else Debug.Log("非Hololens无法导出锚点!!!"); #endif }