コード例 #1
0
ファイル: AnchorShared.cs プロジェクト: comblox/METoolkit
        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;
        }
コード例 #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;
     }
 }
コード例 #3
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);
            }
        }
コード例 #4
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;
        }
    }
コード例 #5
0
    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);
    }
コード例 #6
0
 private void OnExportComplete(SerializationCompletionReason completionReason)
 {
     if (completionReason == SerializationCompletionReason.Succeeded)
     {
         State = States.Anchored;
     }
     else
     {
         Debug.LogErrorFormat("Failed to export Anchor; {0}", completionReason.ToString());
     }
 }
コード例 #7
0
    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");
        }
    }
コード例 #8
0
 /// <summary>
 /// 房主导出锚点成功
 /// </summary>
 /// <param name="completionReason"></param>
 private void ExportComplete(SerializationCompletionReason completionReason)
 {
     if (completionReason == SerializationCompletionReason.Succeeded && exportingAnchorBytes.Count > minTrustworthySerializedAnchorDataSize)
     {
         // 将锚点数据上传至当前房间中
         roomManager.UploadAnchor(
             currentRoom,
             new XString(ExportingAnchorName),
             exportingAnchorBytes.ToArray(),
             exportingAnchorBytes.Count);
     }
     else
     {
         debug("导出锚点出错!" + completionReason.ToString());
         currentState = ImportExportState.InitialAnchorRequired;
     }
 }
コード例 #9
0
    private void OnImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch)
    {
        if (completionReason == SerializationCompletionReason.Succeeded)
        {
            if (PlaySpaceManager.Instance.Floor.GetComponent <WorldAnchor>())
            {
                Destroy(PlaySpaceManager.Instance.Floor.GetComponent <WorldAnchor>());
            }

            deserializedTransferBatch.LockObject(PlaySpaceManager.Instance.Floor.name, PlaySpaceManager.Instance.Floor);

            State = States.Anchored;
        }
        else
        {
            Debug.LogErrorFormat("Failed to import Anchor; {0}", completionReason.ToString());
        }
    }
コード例 #10
0
 private void AnchorImportHandler(SerializationCompletionReason status, WorldAnchorTransferBatch watb)
 {
     if (status == SerializationCompletionReason.Succeeded)
     {
         // Load Imported Anchor
         Debug.Log("Anchor Import Handler");
         DeleteObjectAnchor();
         anchorStore.Delete(AnchorName);
         worldAnchor = watb.LockObject(AnchorName, anchoredObject);
         anchorStore.Save(AnchorName, worldAnchor);  // Force Save when sent as a located network anchor
         worldAnchor.OnTrackingChanged += WorldAnchor_OnTrackingChanged;
         CurrentState = ControlState.WaitingForAnchorLocation;
     }
     else
     {
         Debug.LogErrorFormat("AnchorControl: AnchorImportHander Error - {0}", status.ToString());
     }
 }
コード例 #11
0
        void ExportComplete(SerializationCompletionReason completionReason)
        {
            exporting = false;
            if (completionReason != SerializationCompletionReason.Succeeded)
            {
                Debug.LogError("Export Failed due to : " + completionReason.ToString());
                return;
            }

            string fullPath = folderPath + "\\" + anchorFileName + fileExtension;

#if UNITY_WINRT
            UnityEngine.Windows.File.WriteAllBytes(fullPath, storedData.ToArray());
#else
            System.IO.File.WriteAllBytes(fullPath, storedData.ToArray());
#endif
            Debug.Log("Succesfully exported data to path : " + fullPath);
        }
コード例 #12
0
    public void OnExportComplete(SerializationCompletionReason completionReason)
    {
        if (completionReason == SerializationCompletionReason.Succeeded)
        {
            Logger.Log("Export Complete (succeeded)");

            var data = _stream.ToArray();

#if WINDOWS_UWP
            WorldAnchorMgr.Instance.SaveData(data);
#endif
            IsSender = true;
            SendAnchor(data);
        }
        else
        {
            Logger.Log("Export Complete (failure) reason " + completionReason.ToString());
        }
    }
コード例 #13
0
    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);
        }
    }
コード例 #14
0
        //is called from the world anchor transfer batch
        private void onImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch)
        {
            if (importInformation.Equals(default(ImportInformation)))
            {
                return;//already finished to import
            }
            if (completionReason != SerializationCompletionReason.Succeeded)
            {
                Debug.Log("Failed to import: " + completionReason.ToString());
                if (importInformation.retryCount > 0)
                {
                    importInformation.retryCount--;
                    WorldAnchorTransferBatch.ImportAsync(importInformation.anchorData, onImportComplete);
                }
                return;
            }

            opsQueue.Enqueue(new Operation(onImportCompleteForUnity, deserializedTransferBatch));
        }
コード例 #15
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 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;
        }
    }
コード例 #16
0
    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");
        }
    }
コード例 #17
0
        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>());
            }
        }
コード例 #18
0
        //is called from the world anchor transfer batch
        private void onImportComplete(SerializationCompletionReason completionReason, WorldAnchorTransferBatch deserializedTransferBatch)
        {
            if (stopImport)
            {
                exit();
                return;
            }


            if (completionReason != SerializationCompletionReason.Succeeded)
            {
                Debug.Log("Failed to import: " + completionReason.ToString());
                if (retryCount > 0)
                {
                    retryCount--;
                    WorldAnchorTransferBatch.ImportAsync(anchorData, onImportComplete);
                }
                return;
            }

            callbackWhenFinished?.Invoke(deserializedTransferBatch, anchorTime);
        }
コード例 #19
0
    /// <summary>
    /// This is invoked once we've finished exported the binary anchor data to a byte array.
    /// </summary>
    private void ExportAnchorDataComplete(
        int attempts,
        SerializationCompletionReason status,
        byte[] data,
        String anchorId,
        GameObject gameObject,
        ExportingAnchorCompleteDelegate completeDelegate)
    {
        ExportingAnchorResult result = ExportingAnchorResult.Unknown;

        lock (ImportingAndExportingLock)
        {
            if (ImportingAnchorSource.IsValid || ImportedAnchor != null)
            {
                Debug.LogFormat("[NetworkAnchorManager] Exporting anchor completed, but local client is now using a remote anchor. (anchor id: {0}) (bytes: {1}) (export result: {2}) {3}", anchorId, data.Length, status.ToString(), DebugInfo());
                result = ExportingAnchorResult.FailedTimedOut;
            }
            else if (ExportingAnchorSource.AnchorId != anchorId)
            {
                Debug.LogFormat("[NetworkAnchorManager] Exporting anchor completed, but exporting anchor id changed. (anchor id: {0}) (bytes: {1}) {2}", anchorId, data.Length, DebugInfo());
                result = ExportingAnchorResult.FailedInvalidAnchorId;
            }
            else if (status == SerializationCompletionReason.Succeeded)
            {
                Debug.LogFormat("[NetworkAnchorManager] Exporting anchor succeeded. (anchor id: {0}) (bytes: {1}) {2}", anchorId, data.Length, DebugInfo());
                anchorTransmitter.SendData(data);
                result = ExportingAnchorResult.Success;
                ExportingAnchorSource = SharedAnchorData.Empty;
            }
            else
            {
                Debug.LogErrorFormat("[NetworkAnchorManager] Exporting anchor failed, going to retry. (anchor id: {0}) (status: {1}) (bytes: {2}) {3}", anchorId, status, data.Length, DebugInfo());
                StartCoroutine(RetrySharingAnchor(attempts, anchorId, gameObject, completeDelegate));
            }
        }

        if (result != ExportingAnchorResult.Unknown && completeDelegate != null)
        {
            completeDelegate(anchorId, gameObject, result);
        }
    }