Exemple #1
0
        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;
        }
Exemple #2
0
 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;
     }
 }
Exemple #3
0
        /// <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");
            }
        }
Exemple #4
0
    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 ExportComplete(SerializationCompletionReason status)
    {
        if ((status == SerializationCompletionReason.Succeeded) &&
            (exportingAnchorBytes.Count > MinTrustworthySerializedAnchorDataSize))
        {
            StatusTextDisplay.Instance.SetStatusText(
                string.Format(
                    "copying {0:N2}MB data", (exportingAnchorBytes.Count / (1024 * 1024))));

            if (SharingStage.Instance.ShowDetailedLogs)
            {
                Debug.Log("Anchor Manager: Uploading anchor: " + exportingAnchorName);
            }

            roomManager.UploadAnchor(
                currentRoom,
                new XString(exportingAnchorName),
                exportingAnchorBytes.ToArray(),
                exportingAnchorBytes.Count);
        }
        else
        {
            StatusTextDisplay.Instance.SetStatusText("retrying export");

            Debug.LogWarning("Anchor Manager: Failed to upload anchor, trying again...");

            currentState = ExportState.WaitingForAnchorLocation;
        }
    }
Exemple #6
0
        /// <summary>
        /// Called by the WorldAnchorTransferBatch when anchor exporting is complete.
        /// </summary>
        /// <param name="status"></param>
        private void ExportComplete(SerializationCompletionReason status)
        {
            if (status == SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > MinTrustworthySerializedAnchorDataSize)
            {
                if (SharingStage.Instance.ShowDetailedLogs)
                {
                    Debug.Log("Anchor Manager: Uploading anchor: " + exportingAnchorName);
                }

                if (AnchorDebugText != null)
                {
                    AnchorDebugText.text += string.Format("\nUploading anchor: " + exportingAnchorName);
                }

                roomManager.UploadAnchor(
                    currentRoom,
                    new XString(exportingAnchorName),
                    exportingAnchorBytes.ToArray(),
                    exportingAnchorBytes.Count);
            }
            else
            {
                Debug.LogWarning("Anchor Manager: Failed to upload anchor, trying again...");

                if (AnchorDebugText != null)
                {
                    AnchorDebugText.text += string.Format("\nFailed to upload anchor, trying again...");
                }

                currentState = ImportExportState.InitialAnchorRequired;
            }
        }
    private void AnchorExportHandler(SerializationCompletionReason status)
    {
        int dataSize = anchorBytes.Count;

        Debug.LogFormat("AnchorControl: AnchorExportHandler()");
        DisplayStatus("AnchorControl: AnchorExportHandler()");

        if (status == SerializationCompletionReason.Succeeded)
        {
            if (dataSize > MinAnchorDataSize)
            {
                byte[] anchorDataBytes = null;

                AnchorName      = ClientId;
                anchorDataBytes = anchorBytes.ToArray();

                // TODO: SEND anchorDataByes
                Debug.LogFormat("Anchor Data SEND: {0}", dataSize);
            }
            else
            {
                Debug.LogErrorFormat("Anchor Export Min Size Error {0}/{1}", dataSize, MinAnchorDataSize);
            }
        }
        else
        {
            Debug.LogErrorFormat("Anchor Export ERROR");
        }
    }
Exemple #8
0
    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;
        }
    }
Exemple #9
0
    /// <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");
        }
    }
Exemple #10
0
        /// <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;
            }
        }
Exemple #11
0
        private void OnExportComplete(SerializationCompletionReason completionReason)
        {
            if (completionReason != SerializationCompletionReason.Succeeded)
            {
                uploadFinish      = true;
                uploadErrorString = "Excport Anchor Failed";
            }
            else
            {
                Debug.Log("Save Anchor to File");

                try
                {
                    File.WriteAllBytes(anchorFilePath + "/" + anchorFileName, Buffer);
                }
                catch (Exception e)
                {
                    uploadFinish      = true;
                    uploadErrorString = "Save Anchor File Failed [" + anchorFilePath + "/" + anchorFileName + "]";
                }

                if (!uploadFinish)
                {
                    ToUploadAnchorFile(anchorFilePath, anchorFileName);
                }
            }
        }
    /// <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;
        }
    }
Exemple #13
0
    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;
        }
    }
    /// <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;
        }
    }
Exemple #15
0
        //导入完成后,把锚点数据附加到 物体上
        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="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;
        }
 private void OnExportComplete(SerializationCompletionReason completionReason)
 {
     if (completionReason == SerializationCompletionReason.Succeeded)
     {
         State = States.Anchored;
     }
     else
     {
         Debug.LogErrorFormat("Failed to export Anchor; {0}", completionReason.ToString());
     }
 }
 private void OnDataExported(SerializationCompletionReason reason)
 {
     if (reason != SerializationCompletionReason.Succeeded)
     {
         // Something went wrong....
     }
     else
     {
         // It went ok.
         // Inform the client everything worked!
     }
 }
Exemple #19
0
 private void OnExportComplete(SerializationCompletionReason completionReason)
 {
     if (completionReason != SerializationCompletionReason.Succeeded)
     {
         //Failed
     }
     else
     {
         //Success
         exportedData = ms.ToArray();
         Task.Factory.StartNew(() => SaveToFile());
     }
 }
Exemple #20
0
 private void OnExportComplete(SerializationCompletionReason completionReason)
 {
     if (completionReason != SerializationCompletionReason.Succeeded)
     {
         //Failed
     }
     else
     {
         //Success
         exportedData = ms.ToArray();
         //DebugToServer.Log.Send("Total saved data: " + exportedData.Length.ToString());
         Task.Factory.StartNew(() => SaveToFile());
     }
 }
Exemple #21
0
 /// <summary>
 /// Called when a remote anchor has been de-serialized
 /// </summary>
 /// <param name="status">Tracks if the import worked</param>
 /// <param name="batch">The WorldAnchorTransferBatch that has the anchor information.</param>
 private void BatchImportAsyncCompleted(
     SerializationCompletionReason status,
     WorldAnchorTransferBatch batch)
 {
     if (status != SerializationCompletionReason.Succeeded)
     {
         Debug.LogErrorFormat("[NetworkAnchorManager] Anchor import has failed. (status: {0})", status);
         ImportAnchorDataCompleted(null);
     }
     else
     {
         Debug.Log("[NetworkAnchorManager] Anchor import was successful.");
         ImportAnchorDataCompleted(batch);
     }
 }
Exemple #22
0
    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)
        }
    }
    private void OnExportComplete(SerializationCompletionReason completionReason)
    {
        Debug.LogFormat("OnExportComplete {0}", completionReason);

        exporting = false;

        if (completionReason == SerializationCompletionReason.Succeeded)
        {
            RaiseOnAnchored(worldAnchorBuffer.ToArray());
        }
        else
        {
            // TODO: handle expectational case
        }
    }
Exemple #24
0
 private void onExportCompleted(SerializationCompletionReason completionReason)
 {
     if (completionReason == SerializationCompletionReason.Succeeded)
     {
         opsQueue.Enqueue(new Operation(onExportCompletedForUnity, null));
     }
     else if (completionReason == SerializationCompletionReason.AccessDenied)
     {
         Debug.LogError("The export of the worldanchor of the gameobject " + this.gameObject.name + " failed.\nAre you running this on the Hololens or Emulator? Have you enabled Spartial PerceptionCapability?");
     }
     else
     {
         Debug.LogError("The export of the worldanchor of the gameobject " + this.gameObject.name + " failed");
     }
 }
        /// <summary>
        /// Called by the WorldAnchorTransferBatch when anchor exporting is complete.
        /// </summary>
        /// <param name="status">Serialization Status.</param>
        private void ExportComplete(SerializationCompletionReason status)
        {
            if (status == SerializationCompletionReason.Succeeded &&
                rawAnchorUploadData.Count > MinTrustworthySerializedAnchorDataSize)
            {
                if (ShowDetailedLogs)
                {
                    Debug.LogFormat("[SharingWorldAnchorManager] Exporting {0} anchors with {1} bytes.", currentAnchorTransferBatch.anchorCount.ToString(), rawAnchorUploadData.ToArray().Length.ToString());
                }

                if (AnchorDebugText != null)
                {
                    AnchorDebugText.text += string.Format("\nExporting {0} anchors with {1} bytes.",
                                                          currentAnchorTransferBatch.anchorCount.ToString(),
                                                          rawAnchorUploadData.ToArray().Length.ToString());
                }

                string[] anchorNames = currentAnchorTransferBatch.GetAllIds();

                for (var i = 0; i < anchorNames.Length; i++)
                {
                    SharingStage.Instance.Manager.GetRoomManager().UploadAnchor(
                        SharingStage.Instance.CurrentRoom,
                        new XString(anchorNames[i]),
                        rawAnchorUploadData.ToArray(),
                        rawAnchorUploadData.Count);
                }
            }
            else
            {
                Debug.LogWarning("[SharingWorldAnchorManager] Failed to upload anchor!");

                if (AnchorDebugText != null)
                {
                    AnchorDebugText.text += "\nFailed to upload anchor!";
                }

                if (rawAnchorUploadData.Count < MinTrustworthySerializedAnchorDataSize)
                {
                    Debug.LogWarning("[SharingWorldAnchorManager] Anchor data was not valid.  Try creating the anchor again.");

                    if (AnchorDebugText != null)
                    {
                        AnchorDebugText.text += "\nAnchor data was not valid.  Try creating the anchor again.";
                    }
                }
            }
        }
    private void OnImportPanelDataComplete(GameObject panelObjectToAnchor
                                           , SerializationCompletionReason completionReason
                                           , WorldAnchorTransferBatch batch)
    {
        if (completionReason != SerializationCompletionReason.Succeeded)
        {
            Debug.Log("Import failed! Retrying load...");
            LoadAllPanelAnchorsFromDisk(panelObjectToAnchor);
            return;
        }

        ProgressIndicator.Instance.SetMessage("Instantiating panels with World Anchors..");
        ProgressIndicator.Instance.SetProgress(0.60f);

        InstantiateFixedPanels(batch, panelObjectToAnchor);
    }
Exemple #27
0
 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;
 }
Exemple #28
0
 /// <summary>
 /// Called when serializing an anchor is complete.
 /// </summary>
 /// <param name="status">If the serialization succeeded.</param>
 private void ExportComplete(SerializationCompletionReason status)
 {
     if (status == SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > minTrustworthySerializedAnchorDataSize)
     {
         AnchorName = exportingAnchorName;
         anchorData = exportingAnchorBytes.ToArray();
         GenericNetworkTransmitter.Instance.SetData(anchorData);
         createdAnchor = true;
         Debug.Log("Anchor ready");
         GenericNetworkTransmitter.Instance.ConfigureAsServer();
     }
     else
     {
         CreateAnchor();
     }
 }
Exemple #29
0
    /// <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;
        }
    }
 /// <summary>
 /// Called when a remote anchor has been de-serialized
 /// </summary>
 /// <param name="status">Tracks if the import worked</param>
 /// <param name="batch">The WorldAnchorTransferBatch that has the anchor information.</param>
 private void BatchImportAsyncCompleted(
     string anchorId,
     SerializationCompletionReason status,
     WorldAnchorTransferBatch batch,
     byte[] anchorData)
 {
     if (status == SerializationCompletionReason.Succeeded && batch.anchorCount > 0)
     {
         Debug.Log("[NetworkAnchorManager] Anchor import was successful.");
         ImportAnchorDataCompleted(batch);
     }
     else
     {
         Debug.LogErrorFormat("[NetworkAnchorManager] Anchor import has failed, retrying (status: {0}) (batch.anchorCount: {1})", status, batch.anchorCount);
         StartCoroutine(RetryImportingAnchor(anchorId, anchorData));
     }
 }
 /// <summary>
 /// Called when serializing an anchor is complete.
 /// </summary>
 /// <param name="status">If the serialization succeeded.</param>
 private void ExportComplete(SerializationCompletionReason status)
 {
     if (status == SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > minTrustworthySerializedAnchorDataSize)
     {
         AnchorName = exportingAnchorName;
         anchorData = exportingAnchorBytes.ToArray();
         GenericNetworkTransmitter.Instance.SetData(anchorData);
         createdAnchor = true;
         Debug.Log("Anchor ready");
         GenericNetworkTransmitter.Instance.ConfigureAsServer();
         AnchorEstablished = true;
     }
     else
     {
         CreateAnchor();
     }
 }
    /// <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);
            ImportInProgress = false;
            AnchorEstablished = true;
        }
        else
        {
            // if we failed, we can simply try again.
            gotOne = true;
            Debug.Log("Import fail");
        }
    }
 private static void InvokeWorldAnchorDeserializationCompleteDelegate(DeserializationCompleteDelegate onDeserializationComplete, SerializationCompletionReason completionReason, IntPtr nativePtr)
 {
     WorldAnchorTransferBatch deserializedTransferBatch = new WorldAnchorTransferBatch(nativePtr);
     onDeserializationComplete(completionReason, deserializedTransferBatch);
 }
 private static void InvokeWorldAnchorSerializationCompleteDelegate(SerializationCompleteDelegate onSerializationComplete, SerializationCompletionReason completionReason)
 {
     onSerializationComplete(completionReason);
 }