private void OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch) { if (completionReason != SerializationCompletionReason.Succeeded) { Debug.Log("Failed to import: " + completionReason.ToString()); if (retryCount > 0) { retryCount--; WorldAnchorTransferBatch.ImportAsync(importedData, OnImportComplete); } else { cbImportFinish(false, "Import Anchor Failed after retry times.", null); cbImportFinish = null; } return; } Debug.Log("Import success!"); if (File.Exists(anchorFilePath + "/" + anchorFileName)) { File.Delete(anchorFilePath + "/" + anchorFileName); } cbImportFinish(true, null, deserializedTransferBatch); cbImportFinish = null; }
private void ContinueDownload() { Debug.Log("Load data from file"); // 读取文件 try { importedData = File.ReadAllBytes(anchorFilePath + "/" + anchorFileName); } catch (Exception e) { Debug.Log(e); downloadErrorString = e.ToString(); cbImportFinish(false, "Load file error! " + e, null); cbImportFinish = null; return; } Debug.Log("Download, data size=" + importedData.Length + " , Begin to Import!"); if (importedData.Length != 0) { retryCount = 3; WorldAnchorTransferBatch.ImportAsync(importedData, OnImportComplete); } else { cbImportFinish(false, "Anchor data is wrong!", null); cbImportFinish = null; } }
void Update() { #if UNITY_WSA && !UNITY_EDITOR if (SharingStage.Instance.IsConnected) { switch (currentState) { case ImportState.Start: ConnectToRoom(); this.currentState = ImportState.ReadyToImport; break; case ImportState.ReadyToImport: MakeAnchorDataRequest(); break; case ImportState.DataDownloadedReadyForImport: // DataReady is set when the anchor download completes. currentState = ImportState.Importing; StatusTextDisplay.Instance.SetStatusText("importing synchronisation data"); WorldAnchorTransferBatch.ImportAsync(rawAnchorData, ImportComplete); break; } } #endif }
/// <summary> /// Sets the world anchor at the origin from data if succeeded. /// </summary> public static void ShareOriginComplete(string clusterID, bool succeeded) { if (succeeded && clusterID != shareID && _shareData != null) { if (MixedRealityDisplay.currentDisplay.shareOrigin) { WorldAnchorTransferBatch.ImportAsync(_shareData.ToArray(), (SerializationCompletionReason completionReason, WorldAnchorTransferBatch batch) => { if (completionReason != SerializationCompletionReason.Succeeded) { return; } // Disable the origin finder if it exists if (_originFinder != null) { _originFinder.Disable(); _originFinder = null; } // Create the world anchor SetWorldAnchor(batch.LockObject(MixedRealityDisplay.currentDisplayConfig.id, worldAnchor == null ? new GameObject("WorldAnchor") : worldAnchor.gameObject)); }); } } _shareData = null; }
private void Update() { #if WINDOWS_UWP if (HolographicSettings.IsDisplayOpaque) { return; } if (gotOne) { Debug.Log("importing"); gotOne = false; ImportInProgress = true; WorldAnchorTransferBatch.ImportAsync(anchorData, ImportComplete); } if (oldAnchorName != AnchorName && !createdAnchor) { Debug.LogFormat("New anchor name {0} => {1}", oldAnchorName, AnchorName); oldAnchorName = AnchorName; if (string.IsNullOrEmpty(AnchorName)) { Debug.Log("anchor is empty"); AnchorEstablished = false; } else if (!AttachToCachedAnchor(AnchorName)) { Debug.Log("requesting download of anchor data"); WaitForAnchor(); } } #else return; #endif }
private void Update() { switch (currentState) { // If the local anchor store is initialized. case ImportExportState.AnchorStore_Initialized: if (sharingServiceReady) { InitRoomApi(); } break; case ImportExportState.RoomApiInitialized: StartAnchorProcess(); break; case ImportExportState.DataReady: // DataReady is set when the anchor download completes. currentState = ImportExportState.Importing; WorldAnchorTransferBatch.ImportAsync(rawAnchorData, ImportComplete); break; case ImportExportState.InitialAnchorRequired: currentState = ImportExportState.CreatingInitialAnchor; CreateAnchorLocally(); break; case ImportExportState.ReadyToExportInitialAnchor: // We've created an anchor locally and it is ready to export. currentState = ImportExportState.UploadingInitialAnchor; Export(); break; } }
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 sr = GameObject.Find("RefernceSceneBuilder"); if (sr != null) { deserializedTransferBatch.LockObject("1_GC35L", sr); CompleteWaTime.text = Time.time.ToString(); SendMsg sendstr = new SendMsg("SyncPlantNum:" + IF.text); startSocketTime.text = Time.time.ToString(); tCP.SocketSendByte(sendstr); } else { Debug.Log("Failed to find object for anchor id: " + "1_GC35L"); indicator.GetComponent <MeshRenderer>().material.color = Color.red; } }
private void Update() { #if UNITY_WSA #if UNITY_2017_2_OR_NEWER if (HolographicSettings.IsDisplayOpaque) { return; } #else if (!VRDevice.isPresent) { return; } #endif if (gotOne) { _ = ProgressIndicator.StartProgressIndicator("Importing anchor data..."); Debug.Log("Importing"); gotOne = false; IsImportInProgress = true; WorldAnchorTransferBatch.ImportAsync(anchorData, ImportComplete); } #endif }
static async Task <bool> ImportWorldAnchorToGameObjectAsync( GameObject gameObject, byte[] worldAnchorBits) { var completion = new TaskCompletionSource <bool>(); bool worked = false; WorldAnchorTransferBatch.ImportAsync(worldAnchorBits, (reason, batch) => { if (reason == SerializationCompletionReason.Succeeded) { var anchorId = batch.GetAllIds().FirstOrDefault(); if (!string.IsNullOrEmpty(anchorId)) { batch.LockObject(anchorId, gameObject); worked = true; } } batch.Dispose(); completion.SetResult(true); } ); await completion.Task; return(worked); }
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; } }
public void StartSyncSinglePlant(byte[] data, GameObject indicator1) { anchorData = data; indicator = indicator1; indicator1.GetComponent <MeshRenderer>().material.color = Color.black; WorldAnchorTransferBatch.ImportAsync(data, OnImportComplete); }
internal WorldAnchorImport(byte[] anchor, UnityAction <WorldAnchorTransferBatch, DateTime> callbackWhenFinished, DateTime anchorTime, int retryCount = 3) { this.retryCount = retryCount; this.callbackWhenFinished = callbackWhenFinished; this.anchorTime = anchorTime; this.anchorData = anchor; WorldAnchorTransferBatch.ImportAsync(anchor, onImportComplete); }
private void Update() { if (_import) { // Import the world anchor... WorldAnchorTransferBatch.ImportAsync(_anchorData, OnImportComplete); _import = false; } }
/// <summary> /// 导入锚点 /// </summary> /// <param name="data">锚点数据</param> /// <param name="obj">要导入锚点数据的物体</param> public void ImportAnchor(byte[] data, GameObject obj) { Debug.Log("导入锚点数据"); objectToImportAnchor = obj; #if !UNITY_EDITOR && UNITY_WSA WorldAnchorTransferBatch.ImportAsync(data, ImportComplete); #else Debug.Log("非Hololens无法入锚点数据"); #endif }
public async void LoadAllColumnAnchorsFromDisk(GameObject columnObjectToAnchor) { OnLoadAnchorsFromDiskStarted(); ProgressIndicator.Instance.SetMessage("Finding data file.."); #if WINDOWS_UWP IStorageItem item = await storageFolder.TryGetItemAsync(columnDataFileName); if (item == null) { Debug.LogFormat("Unable to locate data file at: {0}!", storageFolder.Path); Dialog.Open(PrefabsManager.Instance.dialogPrefab , DialogButtonType.OK , "Error" , string.Format("Unable to locate data file at: {0}!", storageFolder.Path)); return; } else { Debug.Log("Found column anchor data file!"); } StorageFile dataFile = (StorageFile)item; IBuffer buffer = await FileIO.ReadBufferAsync(dataFile); byte[] dataByteArray = new byte[buffer.Length]; using (DataReader dataReader = DataReader.FromBuffer(buffer)) { dataReader.ReadBytes(dataByteArray); } ProgressIndicator.Instance.SetMessage("Found file. Now importing World Anchors.."); ProgressIndicator.Instance.SetProgress(0.10f); Debug.LogFormat("Number of bytes read: {0}", dataByteArray.Length); WorldAnchorTransferBatch.ImportAsync(dataByteArray , (completionReason, batch) => OnImportColumnDataComplete(completionReason, batch, columnObjectToAnchor)); #else Debug.Log("Unable to load anchor data from file as this is not a UWP system."); Dialog.Open(PrefabsManager.Instance.dialogPrefab , DialogButtonType.OK , "Error" , "Unable to load anchor data from file as this is not a UWP system."); OnLoadAnchorsFromDiskCompleted(new Dictionary <String, GameObject>()); #endif }
private void ImportWorldAnchor(byte[] importedData) { debugText.text += "Started GameRootAnchor import |"; foreach (byte number in importedData) { debugText.text += number; } debugText.text += "|"; WorldAnchorTransferBatch.ImportAsync(importedData, OnImportComplete); }
private void onAnchorDataAvailable(MqttNetClientAccess.mqttMessage message) { DateTime anchorTime = TimeMethodesForAnchors.parseAnchor(message.topic).Value; importInformation = new ImportInformation(3, message.payload, anchorTime); //TODO: what happens when one anchor gets available while the other is currently importing //then we should somehow stop the import of the other and use the new //we have the anchor now AppDataExportManager.Instance.unsubscribe(message.topic, onAnchorDataAvailable); WorldAnchorTransferBatch.ImportAsync(message.payload, onImportComplete); }
void Update() { if (roomManagerCallbacks == null && SharingStage.Instance != null && SharingStage.Instance.SessionUsersTracker != null) { // We will register for session joined to indicate when the sharing service // is ready for us to make room related requests. SharingStage.Instance.SessionUsersTracker.UserJoined += SessionUsersTracker_UserJoined; // Setup the room manager callbacks. roomManager = SharingStage.Instance.Manager.GetRoomManager(); roomManagerCallbacks = new RoomManagerAdapter(); roomManagerCallbacks.AnchorsDownloadedEvent += RoomManagerCallbacks_AnchorsDownloaded; roomManagerCallbacks.AnchorUploadedEvent += RoomManagerCallbacks_AnchorUploaded; roomManager.AddListener(roomManagerCallbacks); } switch (currentState) { // If the local anchor store is initialized. case ImportExportState.AnchorStore_Initialized: if (sharingServiceReady) { InitRoomApi(); } break; case ImportExportState.RoomApiInitialized: StartAnchorProcess(); break; case ImportExportState.DataReady: // DataReady is set when the anchor download completes. currentState = ImportExportState.Importing; WorldAnchorTransferBatch.ImportAsync(rawAnchorData, ImportComplete); break; case ImportExportState.InitialAnchorRequired: currentState = ImportExportState.CreatingInitialAnchor; CreateAnchorLocally(); break; case ImportExportState.ReadyToExportInitialAnchor: // We've created an anchor locally and it is ready to export. currentState = ImportExportState.UploadingInitialAnchor; Export(); break; } }
bool SetAnchor(byte[] data) { State = States.Importing; #if WINDOWS_UWP worldAnchorBuffer.Clear(); worldAnchorBuffer.AddRange(data); WorldAnchorTransferBatch.ImportAsync(data, OnImportComplete); #else State = States.Anchored; #endif return(true); }
private void OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch) { if (completionReason != SerializationCompletionReason.Succeeded) { //Import failed if (retryCount > 0) { retryCount--; WorldAnchorTransferBatch.ImportAsync(importedData, OnImportComplete); } return; } importedAnchor = deserializedTransferBatch.LockObject(importAnchorName, gameObjectToSet); isRequestActive = false; isRequestFinished = true; }
// Update中处理各种状态(简单状态机) private void Update() { if (currentState != lastState) { debug("状态变化:" + lastState.ToString() + " > " + currentState.ToString()); lastState = currentState; } lblMsg.text = sb.ToString(); switch (currentState) { case ImportExportState.AnchorStore_Initialized: // 本地锚点存储器初始化完成 // 如果成功加入当前会话,则开始加载房间 if (sharingServiceReady) { InitRoomApi(); } break; case ImportExportState.RoomApiInitialized: // 房间已加载完成,开始加载锚点信息 StartAnchorProcess(); break; case ImportExportState.DataReady: // 锚点数据下载完成后,开始导入锚点数据 currentState = ImportExportState.Importing; WorldAnchorTransferBatch.ImportAsync(rawAnchorData, ImportComplete); break; case ImportExportState.InitialAnchorRequired: // 房主房间创建完成后,需要创建初始锚点共享给他人 currentState = ImportExportState.CreatingInitialAnchor; // 创建本地锚点 CreateAnchorLocally(); break; case ImportExportState.ReadyToExportInitialAnchor: // 准备导出初始锚点 currentState = ImportExportState.UploadingInitialAnchor; // 执行导出 Export(); break; } }
private void OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch) { if (completionReason != SerializationCompletionReason.Succeeded) { Debug.Log("Failed to import: " + completionReason.ToString()); debugText.text += "Failed to import: " + completionReason.ToString(); if (retryCount > 0) { retryCount--; WorldAnchorTransferBatch.ImportAsync(importedWorldAnchor, OnImportComplete); } return; } debugText.text += "GameRootAnchor Imported!!! |"; deserializedTransferBatch.LockObject("GameRootAnchor", WorldCenter); }
void Update() { switch (currentState) { // If the local anchor store is initialized. case ImportExportState.AnchorStore_Initialized: if (sharingServiceReady) { InitRoomApi(); } break; case ImportExportState.RoomApiInitialized: StartAnchorProcess(); break; case ImportExportState.DataReady: // DataReady is set when the anchor download completes. currentState = ImportExportState.Importing; WorldAnchorTransferBatch.ImportAsync(rawAnchorData, ImportComplete); break; case ImportExportState.InitialAnchorRequired: //currentState = ImportExportState.CreatingInitialAnchor; //CreateAnchorLocally(); DisplayUI.Instance.AppendText("ImportExportAnchors() - State:InitalAnchorRequired"); if (anchorStore.anchorCount > 0) { currentState = ImportExportState.ReadyToExportInitialAnchor; } else { DisplayUI.Instance.AppendText("ImportExportAnchors() - State:InitalAnchorRequired ERROR NO ANCHORS!"); } break; case ImportExportState.ReadyToExportInitialAnchor: // We've created an anchor locally and it is ready to export. currentState = ImportExportState.UploadingInitialAnchor; DisplayUI.Instance.AppendText("ImportExportAnchors() - State:UploadingInitialAnchor"); //Export(); ExportFromAnchorStore(); break; } }
// Called by NetworkControl to load new Anchor public bool ImportAnchorData(byte[] anchorData) { if (anchorStore != null) { Debug.Log("Importing Anchor"); if (currentState == ControlState.PlaceAnchor) { CancelAnchor(); } WorldAnchorTransferBatch.ImportAsync(anchorData, AnchorImportHandler); return(true); } else { Debug.LogError("Importing Anchor: Anchor Store Not Ready"); return(false); } }
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 Update() { if (gotOne) { Debug.Log("importing"); gotOne = false; WorldAnchorTransferBatch.ImportAsync(anchorData, ImportComplete); } if (oldAnchorName != AnchorName && !createdAnchor) { Debug.LogFormat("New anchor name {0} {1}", oldAnchorName, AnchorName); oldAnchorName = AnchorName; if (!AttachToCachedAnchor(AnchorName)) { WaitForAnchor(); } } }
private void OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch) { Debug.LogFormat("OnImportComplete {0}", completionReason); importing = false; if (completionReason != SerializationCompletionReason.Succeeded) { if (importAttempts > 0) { importing = true; importAttempts--; WorldAnchorTransferBatch.ImportAsync(worldAnchorBuffer.ToArray(), OnImportComplete); } return; } worldAnchor = deserializedTransferBatch.LockObject(gameObject.name, gameObject); }
private void Update() { #if WINDOWS_UWP if (UnityEngine.XR.WSA.HolographicSettings.IsDisplayOpaque) { return; } if (gotOne) { Debug.Log("importing"); gotOne = false; ImportInProgress = true; WorldAnchorTransferBatch.ImportAsync(anchorData, ImportComplete); } #else return; #endif }
/// <summary> /// Called to begin the process of importing pending anchor data /// </summary> private void RequestAnchorDataCompleted(GenericNetworkTransmitter sender, RequestDataCompletedArgs args) { if (!args.Successful) { Debug.LogErrorFormat("[NetworkAnchorManager] Failed to receive anchor data. {0}", DebugInfo()); ImportAnchorDataCompleted(null); return; } if (args.Data == null || args.Data.Length == 0) { Debug.LogErrorFormat("[NetworkAnchorManager] Binary anchor data is null or empty, ignoring request to import anchor data. {0}", DebugInfo()); ImportAnchorDataCompleted(null); return; } Debug.LogFormat("[NetworkAnchorManager] Starting import of binary anchor data. (bytes: {0}) {1}", args.Data.Length, DebugInfo()); WorldAnchorTransferBatch.ImportAsync(args.Data, BatchImportAsyncCompleted); }
public override void RestoreWorldAnchor(string anchorId, AnchorRestoredDelegate anchorRestored) { if (isDisplayOpaque) { base.RestoreWorldAnchor(anchorId, anchorRestored); return; } if (string.IsNullOrEmpty(anchorId)) { if (anchorRestored != null) { anchorRestored(null, "InvalidAnchorId"); } return; } if (memBuffer == null || memBuffer.Length == 0) { if (anchorRestored != null) { anchorRestored(null, "AnchorDataNotSet"); } return; } WorldAnchorTransferBatch.ImportAsync(memBuffer, (result, batch) => { GameObject anchorObj = null; if (result == SerializationCompletionReason.Succeeded) { anchorObj = new GameObject(anchorId); batch.LockObject(anchorId, anchorObj); } if (anchorRestored != null) { anchorRestored(result == SerializationCompletionReason.Succeeded ? anchorObj : null, result == SerializationCompletionReason.Succeeded ? string.Empty : result.ToString()); } }); }