/// <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(SerializationCompletionReason status, WorldAnchorTransferBatch wat) { if (status == SerializationCompletionReason.Succeeded && wat.GetAllIds().Length > 0) { Debug.Log("Import complete"); string first = wat.GetAllIds()[0]; Debug.Log("Anchor name: " + first); WorldAnchor existingAnchor = objectToAnchor.GetComponent <WorldAnchor>(); if (existingAnchor != null) { DestroyImmediate(existingAnchor); } WorldAnchor anchor = wat.LockObject(first, objectToAnchor); WorldAnchorManager.Instance.AnchorStore.Save(first, anchor); } 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> void ImportComplete(SerializationCompletionReason status, WorldAnchorTransferBatch wat) { if (status == SerializationCompletionReason.Succeeded && wat.GetAllIds().Length > 0) { Debug.Log("Import complete"); string first = wat.GetAllIds()[0]; Debug.Log("Anchor name: " + first); WorldAnchor anchor = wat.LockObject(first, gameObject); anchorStore.Save(first, anchor); CurrentState = ImportExportState.Ready; GameObject.Find("HologramCollection").GetComponent <Holoscanner.RemoteMeshManager>().anchorSet = true; //GameObject.Find("orb").GetComponent<OrbPlacement>().setComponentsEnabled(true); //WorldAnchor a = GetComponent<WorldAnchor>(); Debug.Log(gameObject.transform.position); Debug.Log(gameObject.transform.rotation); GameObject.Find("HologramCollection").GetComponent <Holoscanner.RemoteMeshManager>().worldtransform = gameObject.transform; //GameObject.Find("HologramCollection").GetComponent<Holoscanner.RemoteMeshManager>().SendTargetRequest(); } else { Debug.Log("Import fail"); CurrentState = ImportExportState.DataReady; } }
//导入完成后,把锚点数据附加到 物体上 private void ImportComplete(SerializationCompletionReason status, WorldAnchorTransferBatch wat) { MYDialog.Instance.Write(status.ToString() + wat.GetAllIds().Length); if (status == SerializationCompletionReason.Succeeded && wat.GetAllIds().Length > 0) { MYDialog.Instance.Write("\r\n导入完成!"); string first = wat.GetAllIds()[0]; Debug.Log("锚点名字: " + first); WorldAnchor existingAnchor = objectToImportAnchor.GetComponent <WorldAnchor>(); if (existingAnchor != null) { //删除旧的锚点数据 DestroyImmediate(existingAnchor); } //绑定新的锚点数据 Debug.Log(objectToImportAnchor.transform.position); WorldAnchor anchor = wat.LockObject(first, objectToImportAnchor); //AnchorStore.Save(first, anchor); MYDialog.Instance.Write("新锚点建立完成!\r\n待此文字位置与发送锚点的hololens看到的位置相同时\r\n锚点同步过程完成"); IsImportAnchor = true; OperationBean op = new OperationBean(); op.op = OperationBean.OpId.AnchorImported; SpectatorViewManager._instance.operationQueue.Enqueue(op); } else { Debug.Log("锚点导入失败!"); OperationBean op = new OperationBean(); op.op = OperationBean.OpId.AnchorImportFailed; SpectatorViewManager._instance.operationQueue.Enqueue(op); } }
/// <summary> /// Called when a remote anchor has been deserialized /// </summary> /// <param name="status"></param> /// <param name="wat"></param> private void OnImportComplete(SerializationCompletionReason status, WorldAnchorTransferBatch wat) { if (status == SerializationCompletionReason.Succeeded && wat.GetAllIds().Length > 0) { Debug.Log("Import complete"); string first = wat.GetAllIds()[0]; Debug.Log("Anchor name: " + first); // Try zeroing out the local position & rotation gameObject.transform.localPosition = new Vector3(); gameObject.transform.localRotation = new Quaternion(); WorldAnchor anchor = wat.LockObject(first, gameObject); currentState = ImportExportState.Ready; if (audioSource != null) { audioSource.Play(); } } else { Debug.Log("Import fail"); currentState = ImportExportState.DataReady; } }
/// <summary> /// Called when a remote anchor has been deserialized /// </summary> /// <param name="status"></param> /// <param name="wat"></param> private void ImportComplete(SerializationCompletionReason status, WorldAnchorTransferBatch wat) { if (status == 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); } WorldAnchor anchor = wat.LockObject(first, gameObject); anchorStore.Save(first, anchor); } AnchorLoadComplete(); } else { Debug.LogError("Import failed"); currentState = ImportExportState.DataReady; } }
private void OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch wat) { if (completionReason == SerializationCompletionReason.Succeeded) { Logger.Log("World Anchor Import Complete (succeeded)"); if (wat.GetAllIds().Length > 0) { string first = wat.GetAllIds()[0]; Logger.Log("Anchor name: " + first); WorldAnchor anchor = wat.LockObject(first, rootSharedObject); rootSharedObject.transform.position += anchor.transform.position; Logger.Log("Game Object " + gameObject.name + " locked with world anchor " + anchor != null ? anchor.name : "NULL"); if (WorldAnchorStore != null) { WorldAnchorStore.Save(first, anchor); } } } else { Logger.Log("World Anchor Import Failed - reason " + completionReason); } }
void ImportComplete(SerializationCompletionReason status, WorldAnchorTransferBatch anchorBatch) { if (status == SerializationCompletionReason.Succeeded) { if (anchorBatch.GetAllIds().Length > 0) { string first = anchorBatch.GetAllIds()[0]; if (SharingStage.Instance.ShowDetailedLogs) { Debug.Log("Anchor Manager: Sucessfully imported anchor " + first); } this.worldAnchor = anchorBatch.LockObject(first, gameObject); StatusTextDisplay.Instance.SetStatusText("synchronised"); } base.FireCompleted(true); } else { StatusTextDisplay.Instance.SetStatusText("retrying synchronisation"); Debug.LogError("Anchor Manager: Import failed"); currentState = ImportState.DataDownloadedReadyForImport; } }
/// <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(SerializationCompletionReason status, WorldAnchorTransferBatch wat) { if (status == SerializationCompletionReason.Succeeded && wat.GetAllIds().Length > 0) { Debug.Log("Import complete"); string first = wat.GetAllIds()[0]; Debug.Log("Anchor name: " + first); WorldAnchor existingAnchor = objectToAnchor.GetComponent <WorldAnchor>(); if (existingAnchor != null) { DestroyImmediate(existingAnchor); } 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 OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch) { if (completionReason != SerializationCompletionReason.Succeeded) { Debug.Log("Failed to import: " + completionReason.ToString()); if (retryCount > 0) { indicator.GetComponent <MeshRenderer>().material.color = Color.cyan; WorldAnchorTransferBatch.ImportAsync(anchorData, OnImportComplete); } return; } if (deserializedTransferBatch.GetAllIds().Length == 0) { if (retryCount > 0) { indicator.GetComponent <MeshRenderer>().material.color = Color.cyan; WorldAnchorTransferBatch.ImportAsync(anchorData, OnImportComplete); } return; } if (gameObject != null) { indicator.GetComponent <MeshRenderer>().material.color = Color.green; deserializedTransferBatch.LockObject(gameObject.name, gameObject); transform.parent.GetComponent <SetRefObjToCertain>().totalSyncNum++; gameObject.SetActive(true); } else { indicator.GetComponent <MeshRenderer>().material.color = Color.red; } }
/// <summary> /// Given a transfer batch, apply only the first anchor id to this object's gameObject. /// </summary> /// <param name="batch"></param> /// <returns>True if gameObject is anchored</returns> public bool ApplyAnchor(WorldAnchorTransferBatch batch, bool saveAchor) { #if UNITY_WSA TargetGameObject = TargetGameObject == null ? gameObject : TargetGameObject; if (saveAchor) { _isAnchored = saveLoad.ApplySharedLocation(TargetGameObject, batch, worldAnchorStore); } else { ClearAnchor(false); var batchIds = batch.GetAllIds(); if (batchIds.Length > 0) { batch.LockObject(batchIds[0], TargetGameObject); _isAnchored = true; } else { _isAnchored = false; } } #endif return(_isAnchored); }
/// <summary> /// 锚点数据下载完成后,开始导入锚点数据 /// </summary> /// <param name="completionReason"></param> /// <param name="deserializedTransferBatch"></param> private void ImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch) { if (completionReason == SerializationCompletionReason.Succeeded && deserializedTransferBatch.GetAllIds().Length > 0) { // 成功导入锚点 // 获取第一个锚点名称 bool hasAnchorName = false; string[] anchorNames = deserializedTransferBatch.GetAllIds(); foreach (var an in anchorNames) { if (an == ExportingAnchorName) { hasAnchorName = true; break; } } if (!hasAnchorName) { currentState = ImportExportState.DataReady; return; } // 保存锚点到本地 WorldAnchor anchor = deserializedTransferBatch.LockObject(ExportingAnchorName, gameObject); if (anchor.isLocated) { if (anchorStore.Save(ExportingAnchorName, anchor)) { currentState = ImportExportState.Ready; } else { currentState = ImportExportState.DataReady; } } else { anchor.OnTrackingChanged += WorldAnchorForImport_OnTrackingChanged; } } else { // 未成功导入,则设置为DataReady,准备在下一帧再次导入,直到导入完成 currentState = ImportExportState.DataReady; } }
// On successful load of WorldAnchors from disk, we iterate through the anchors // instantiate panels using the FixedPanel prefab for each anchor. These objects // are added to a dictionary which is then passed to the OnLoadCompleted method. private void InstantiateFixedPanels(WorldAnchorTransferBatch batch , GameObject panelObjectToAnchor) { Dictionary <String, GameObject> anchorIdToObject = new Dictionary <string, GameObject>(); string[] ids = batch.GetAllIds(); int numAnchorsSkipped = 0; for (int i = 0; i < ids.Length; i++) { ProgressIndicator.Instance.SetProgress(0.60f + i / ids.Length * 0.35f); if (!IsValidPanelAnchorId(ids[i])) { Debug.LogFormat("Found anchor that does not correspond to a panel image target. Skipping load for \"{0}\".", ids[i]); numAnchorsSkipped++; continue; } GameObject panelToAnchor = GameObject.Instantiate(panelObjectToAnchor , panelObjectToAnchor.transform.position , panelObjectToAnchor.transform.rotation); panelToAnchor.transform.localScale = panelObjectLossyScale; if (panelToAnchor == null) { numAnchorsSkipped++; continue; } WorldAnchor anchor = batch.LockObject(ids[i], panelToAnchor); if (anchor == null) { numAnchorsSkipped++; Debug.LogFormat("WorldAnchor with id: {0} could not be locked!", ids[i]); } else { Debug.LogFormat("Loaded WorldAnchor for Panel with id: {0}", ids[i]); //Get WorldAnchorManager to take over tracking of anchor. WorldAnchorManager.Instance.AttachAnchor(panelToAnchor, ids[i]); anchorIdToObject.Add(ids[i], panelToAnchor); } } Dialog.Open(PrefabsManager.Instance.dialogPrefab , DialogButtonType.OK , "Success" , string.Format("{0} WorldAnchors loaded and {1} WorldAnchors skipped!" , ids.Length - numAnchorsSkipped , numAnchorsSkipped)); OnLoadAnchorsFromDiskCompleted(anchorIdToObject); }
/// <summary> /// Called when a remote anchor has been deserialized. /// </summary> /// <param name="status"></param> /// <param name="anchorBatch"></param> private void ImportComplete(SerializationCompletionReason status, WorldAnchorTransferBatch anchorBatch) { bool successful = status == 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 when a remote anchor has been deserialized /// </summary> /// <param name="status"></param> /// <param name="wat"></param> void ImportComplete(SerializationCompletionReason status, WorldAnchorTransferBatch wat) { if (status == SerializationCompletionReason.Succeeded && wat.GetAllIds().Length > 0) { DisplayUI.Instance.AppendText("Import complete"); string first = wat.GetAllIds()[0]; DisplayUI.Instance.AppendText("Anchor name: " + first); WorldAnchor anchor = wat.LockObject(first, gameObject); anchorStore.Save(first, anchor); currentState = ImportExportState.Ready; } else { DisplayUI.Instance.AppendText("Import fail"); currentState = ImportExportState.DataReady; } }
/// <summary> /// Called when a remote anchor has been deserialized. /// </summary> /// <param name="status"></param> /// <param name="wat"></param> void ImportComplete(SerializationCompletionReason status, WorldAnchorTransferBatch wat) { if (status == SerializationCompletionReason.Succeeded && wat.GetAllIds().Length > 0) { UIManager.Instance.LogMessage("Import complete"); Debug.Log("Import complete"); string first = wat.GetAllIds()[0]; Debug.Log("Anchor name: " + first); WorldAnchor anchor = wat.LockObject(first, gameObject); anchorStore.Save(first, anchor); CurrentState = ImportExportState.Ready; AppStateManager.Instance.SetCurrentAppState(AppState.WaitingForGameStart); } else { UIManager.Instance.LogMessage("Import fail"); Debug.Log("Import fail"); CurrentState = ImportExportState.DataReady; } }
/// <summary> /// Called when anchor upload operations complete. /// </summary> private void RoomManagerListener_AnchorUploaded(bool successful, XString failureReason) { if (successful) { string[] anchorIds = currentAnchorTransferBatch.GetAllIds(); for (int i = 0; i < anchorIds.Length; i++) { if (ShowDetailedLogs) { Debug.LogFormat("[SharingWorldAnchorManager] Successfully uploaded anchor \"{0}\".", anchorIds[i]); } if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nSuccessfully uploaded anchor \"{0}\".", anchorIds[i]); } } } else { Debug.LogError("[SharingWorldAnchorManager] Upload failed: " + failureReason); if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nUpload failed: " + failureReason); } } rawAnchorUploadData.Clear(); currentAnchorTransferBatch.Dispose(); currentAnchorTransferBatch = null; isExportingAnchors = false; if (AnchorUploaded != null) { AnchorUploaded(successful); } }
/// <summary> /// WorldAnchorのデシリアライズ完了 (onCompleted) /// </summary> private void ImportComplete(SerializationCompletionReason status, WorldAnchorTransferBatch anchorBatch) { Debug.Log("Import Complete."); if (status == SerializationCompletionReason.Succeeded) { if (anchorBatch.GetAllIds().Length > 0) { // デシリアライズしたアンカーの名前を取得 string first = anchorBatch.GetAllIds()[0]; m_importedAnchorID = first; Debug.Log("Anchor Manager: Sucessfully imported anchor " + first); // アンカーをGameObjectに取り付け現実空間に固定し、ローカルのストアに保存する WorldAnchor anchor = anchorBatch.LockObject(first, m_gameObject); m_anchorStore.Save(first, anchor); } } else { Debug.LogError("Anchor Manager: Import failed"); } }
private void OnImportCompleted(SerializationCompletionReason reason, WorldAnchorTransferBatch batch) { if (reason != SerializationCompletionReason.Succeeded) { // Something went wrong. Retry or abort... return; } var ids = batch.GetAllIds(); foreach (var id in ids) { //batch.LockObject(id) } }
/// <summary> /// Called when a remote anchor has been deserialized. /// </summary> /// <param name="status"></param> /// <param name="anchorBatch"></param> private void ImportComplete(SerializationCompletionReason status, WorldAnchorTransferBatch anchorBatch) { if (status == SerializationCompletionReason.Succeeded) { if (anchorBatch.GetAllIds().Length > 0) { string first = anchorBatch.GetAllIds()[0]; if (SharingStage.Instance.ShowDetailedLogs) { Debug.Log("Anchor Manager: Sucessfully imported anchor " + first); } if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nSucessfully imported anchor " + first); } WorldAnchor anchor = anchorBatch.LockObject(first, gameObject); anchorStore.Save(first, anchor); } AnchorLoadComplete(); } else { Debug.LogError("Anchor Manager: Import failed"); if (AnchorDebugText != null) { AnchorDebugText.text += string.Format("\nImport failed"); } currentState = ImportExportState.DataReady; } }
private void OnReceiveCompleted(SerializationCompletionReason reason, WorldAnchorTransferBatch batch) { if (reason != SerializationCompletionReason.Succeeded) { // Oops.. return; } var allIds = batch.GetAllIds(); foreach (var id in allIds) { GameObject newGuitar = Instantiate(objectToPlace); newGuitar.GetComponent <Identifier>().AnchorName = id; var anchor = batch.LockObject(id, newGuitar); _anchors.Add(id, anchor); } }
private void OnReceiveCompleted(SerializationCompletionReason reason, WorldAnchorTransferBatch batch) { if (reason != SerializationCompletionReason.Succeeded) { // Oops.. Debug.Log("Failed to import: " + reason.ToString()); return; } var allIds = batch.GetAllIds(); foreach (var id in allIds) { GameObject myGameObject = GameObject.Find(id); var anchor = batch.LockObject(id, myGameObject); //_anchors.Add(id, anchor); } }
private void OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch) { if (completionReason != 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"); } }
private void OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch) { if (completionReason != SerializationCompletionReason.Succeeded) { Debug.Log("Failed to import: " + completionReason.ToString()); if (retryCount > 0) { retryCount--; indicator.GetComponent <MeshRenderer>().material.color = Color.cyan; WorldAnchorTransferBatch.ImportAsync(anchorData, OnImportComplete); } return; } GameObject rb = GameObject.Find("anchor1"); if (rb != null) { foreach (string anid in deserializedTransferBatch.GetAllIds()) { Debug.Log("the anchor id contained is: " + anid); if (anid == "anchor1") { deserializedTransferBatch.LockObject(anid, anchorObject1); } else if (anid == "anchor2") { deserializedTransferBatch.LockObject(anid, anchorObject2); } } indicator.GetComponent <MeshRenderer>().material.color = Color.green; TimeCost tc3 = new TimeCost("OFALL", Time.time.ToString() + "successfully locate the anchor"); tCP.SocketSendByte(tc3); syncOrNot = true; //syncPlantInfor = true; } else { Debug.Log("Failed to find object for anchor id: " + spaceId); indicator.GetComponent <MeshRenderer>().material.color = Color.red; } }
private void ImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch) { importing = false; if (completionReason != SerializationCompletionReason.Succeeded) { Debug.LogError("Failed to import due to " + completionReason.ToString()); ImportFromFile(); return; } Debug.Log("Succesfully imported files."); string[] ids = deserializedTransferBatch.GetAllIds(); for (int i = 0; i < ids.Length; ++i) { AnchorStore.Save(ids[i], deserializedTransferBatch.LockObject(ids[i], this.gameObject)); Destroy(GetComponent <WorldAnchor>()); } }
private void OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch) { if (completionReason != SerializationCompletionReason.Succeeded) { Debug.Log("Failed to import: " + completionReason.ToString()); HololensConfigController.Instance.logMessage("Failed to import: " + completionReason.ToString()); if (retryCount > 0) { retryCount--; WorldAnchorTransferBatch.ImportAsync(importedAnchorStoreData, OnImportComplete); } return; } string[] ids = deserializedTransferBatch.GetAllIds(); if (ids != null) { HololensConfigController.Instance.logMessage("Imported: " + ids.Length + " WorldAnchors, now applying..."); foreach (string id in ids) { GameObject obj = GameObject.Find(id); if (obj != null) { deserializedTransferBatch.LockObject(id, obj); HololensConfigController.Instance.logMessage("Imported world anchor for: " + id); //transferBatch.LockObject(id, gameObject); } else { Debug.Log("Failed to find object for anchor id: " + id); HololensConfigController.Instance.logMessage("Failed to find object for anchor id: " + id); } } } else { HololensConfigController.Instance.logMessage("Imported 0 world anchors"); } }
private void OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch) { if (completionReason != SerializationCompletionReason.Succeeded) { //Import failed if (retryCount > 0) { retryCount--; WorldAnchorTransferBatch.ImportAsync(importedData, OnImportComplete); } return; } DebugToServer.Log.Send("Setting world anchor..."); string[] ids = deserializedTransferBatch.GetAllIds(); foreach (string id in ids) { DebugToServer.Log.Send(id); } importedAnchor = deserializedTransferBatch.LockObject(importAnchorName, gameObjectToSet); DebugToServer.Log.Send("World anchor set for " + gameObjectToSet.name); isRequestActive = false; isRequestFinished = true; }
/// <summary> /// Given a transfer batch, apply the batch's first anchor to the given game object. Once applied, attempt to /// save the new anchor to the app's local state. Note that this will delete the previously saved anchor before /// attempting to apply the new anchor. Therefore if the application fails, the old saved anchor will be lost. /// </summary> /// <returns>True if game object is anchored</returns> public bool ApplySharedLocation(GameObject gameObject, WorldAnchorTransferBatch batch, WorldAnchorStore store) { if (gameObject == null) { Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor on null gameObject"); return(false); } if (batch == null) { Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor with null WorldAnchorTransferBatch"); return(false); } var batchIds = batch.GetAllIds(); if (batchIds == null) { Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor with an null id list on WorldAnchorTransferBatch"); return(false); } if (batchIds.Length == 0) { Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor with an empty WorldAnchorTransferBatch"); return(false); } string storageIdString = batchIds[0]; if (String.IsNullOrEmpty(storageIdString)) { Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor with an empty storage id"); return(false); } Guid storageId; try { storageId = new Guid(storageIdString); } catch { Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor with an invalid GUID"); return(false); } if (store == null) { Debug.LogWarning("[PersistenceSaveLoad] Cannot apply a shared WorldAnchor with null WorldAnchorStore"); return(false); } Debug.Log("[PersistenceSaveLoad] Attempting to apply a shared world position: " + storageId); bool successful = false; // delete any previous WorldAnchors on this object DeleteLocation(gameObject, store); RaisePersistenceEvent(PersistenceEventType.ApplyingShared, gameObject, storageIdString); WorldAnchor.OnTrackingChangedDelegate trackingChanged = null; trackingChanged = (WorldAnchor self, bool located) => { if (!located) { Debug.Log("[PersistenceSaveLoad] Haven't located anchor yet: " + storageId); return; } Debug.Log("[PersistenceSaveLoad] Located anchor: " + storageId); self.OnTrackingChanged -= trackingChanged; SaveExistingLocation(storageId, gameObject, store); RaisePersistenceEvent(PersistenceEventType.AppliedShared, gameObject, storageIdString); }; // actually lock the game object to the batch's first anchor WorldAnchor anchor = batch.LockObject(storageIdString, gameObject); if (anchor != null) { anchor.OnTrackingChanged += trackingChanged; trackingChanged(anchor, anchor.isLocated); // assume locating is successful. If a caller wants to trully know when anchor was located, they should // listen for the "AppliedShared" and "Saved" events successful = true; } else { Debug.LogError("[PersistenceSaveLoad] Couldn't lock object with the given storage id: " + storageId); } return(successful); }