Пример #1
0
 // Update is called once per frame
 void Update()
 {
     if (LogText != null)
     {
         if (operationQueue.Count() > 0)
         {
             LogOpBean bean = operationQueue.Dequeue();
             LogText.text    = LogText.text + "\n" + (string)bean.param;
             scrollbar.value = 0.0000000000001f;
         }
     }
 }
Пример #2
0
        void Update()
        {
            while (operationQueue.Count() > 0)
            {
                OperationBean op = operationQueue.Dequeue();
                switch (op.op)
                {
                case OperationBean.OpId.UserEnter:
                    PlayerUserIdList.Add((string)op.param);
                    AddSpectatorViewPlayer((string)op.param, false, false);
                    break;

                case OperationBean.OpId.UserLeave:
                    if (PlayerUserIdList.Contains((string)op.param))
                    {
                        PlayerUserIdList.Remove((string)op.param);
                    }
                    RemoveSpectatorViewPlayer((string)op.param);
                    if (PlayerUserIdList.Count == 0)
                    {
                        // Disconnect();
                    }
                    break;

                case OperationBean.OpId.SelfJoinRoom:
                    AddSpectatorViewPlayer(this.mineUid, true, this.isCreator);
                    SyncInterface.Instance.OnSelfJoinnedRoom(this.roomId, this.isCreator, (Dictionary <string, string[]>)op.param);

                    if (OnConnect != null)
                    {
                        OnConnect.Invoke(this.isCreator, this.isWaittingMarkerDetect);
                    }

                    break;

                case OperationBean.OpId.NetDisconn:
                    if (MrShareData._instance.needLocated)
                    {
                        MrShareData._instance.needLocated = false;
                        MrShareData._instance.FloorTarget.SetActive(false);
                        WaittingForExportAnchor = false;
                    }

                    ClearUserList();
                    PlayerUserIdList.Clear();
                    SetStates(SpectatorViewState.Init);
                    SyncInterface.Instance.OnSelfLeftRoom(roomId);

                    break;

                case OperationBean.OpId.DownAnchor:
                    SetStates(SpectatorViewState.AnchorDownloading);
                    StartCoroutine(DownLoadAnchor());
                    break;

                case OperationBean.OpId.AnchorExported:
                    if (state == SpectatorViewState.AnchorUploading)
                    {
                        StartCoroutine(UploadAnchor());
                    }
                    else
                    {
                        Debug.Log("SV#OperationBean.OpId.AnchorExported#Wrong State. Current State:" + state.ToString());
                    }

                    break;

                case OperationBean.OpId.AnchorImported:
                    if (state == SpectatorViewState.AnchorDownloading)
                    {
                        //停止映射
                        SpatialMappingManager.Instance.StopObserver();
                        MYDialog.Instance.Write("导入锚点完成,设置FloorY为 : " + _lerpStageWithFloor /*,false*/);
                        MrShareData._instance.FloorY = _lerpStageWithFloor;
                        SetStates(SpectatorViewState.AnchorPrepared);
                    }
                    else
                    {
                        Debug.Log("SV#OperationBean.OpId.AnchorImported#Wrong State. Current State:" + state.ToString());
                    }
                    break;

                case OperationBean.OpId.FloorLocated:
                    if (state == SpectatorViewState.LocatingFloor)
                    {
                        SetStates(SpectatorViewState.AnchorUploading);
                        string anchorName = "Anchor" + Guid.NewGuid().ToString();
                        ExportAnchor(anchorName);
                        MYDialog.Instance.Write("你已成功导出锚点  ");
                    }
                    else
                    {
                        Debug.Log("SV#OperationBean.OpId.FloorLocated#Wrong State. Current State:" + state.ToString());
                    }
                    break;

                case OperationBean.OpId.OtherCmd:
                    OtherCmd cmd = (OtherCmd)op.param;
                    SyncInterface.Instance.OnSyncOtherCmd(cmd.id, cmd.cmd);
                    break;

                case OperationBean.OpId.AnchorImportFailed:
                    if (state == SpectatorViewState.AnchorDownloading)
                    {
                        SetStates(SpectatorViewState.ImportAnchorFailed);
                    }
                    else
                    {
                        Debug.Log("SV#OperationBean.OpId.AnchorImportFailed#Wrong State. Current State:" + state.ToString());
                    }
                    break;

                case OperationBean.OpId.MarkerGenerated:
                {
                    MarkerGenerated cmdObj = (MarkerGenerated)op.param;
                    if (OnMarkerGenerated != null)
                    {
                        OnMarkerGenerated(cmdObj.senderid);
                    }
                }
                break;

                case OperationBean.OpId.MarkerDetected:
                {
                    MarkerDetected cmdObj = (MarkerDetected)op.param;
                    if (OnMarkerDetected != null)
                    {
                        OnMarkerDetected(cmdObj.senderid, cmdObj.markerid);
                    }
                }
                break;

                case OperationBean.OpId.SyncWorldRoot:
                {
                    Debug.Log("SpectatorViewManager#Update#SyncWorldRoot");
                    SyncWorldRoot cmdObj = (SyncWorldRoot)op.param;
                    if (OnSyncWorldRoot != null)
                    {
                        OnSyncWorldRoot(cmdObj.senderid, cmdObj.markerid, cmdObj.posx, cmdObj.posy, cmdObj.posz, cmdObj.angley);
                    }
                }
                break;

                case OperationBean.OpId.ios_AdjustFloorLocate:
                {
                    MrShareData._instance.FloorY = _lerpStageWithFloor;

                    Vector3 v = (Vector3)op.param;

                    MrShareData._instance.FloorTarget.transform.localPosition = v;
                    MrShareData._instance.RelativeTransform = MrShareData._instance.FloorTarget.transform;
                    SyncInterface.Instance.OnFloorLocated();
                    MYDialog.Instance.Write("定位地面完成,隐藏log" /*, false*/);
                }
                break;

                case OperationBean.OpId.hololens_AdjustFloorLocate:
                    Vector3 vv = (Vector3)op.param;
                    MrShareData._instance.CreatorLocatePos = vv;
                    break;

                case OperationBean.OpId.OnRoomCache:
                    SyncInterface.Instance.OnRoomCache(roomId, (Dictionary <string, string[]>)op.param);
                    break;
                }
            }
        }
        void Update()
        {
            if (!IsLocolPlayer)
            {
                // 更新位置
                if (headPisitionQueue.Count() > 0)
                {
                    // 包过多则丢包
                    if (headPisitionQueue.Count() > 60)
                    {
                        while (headPisitionQueue.Count() > 5)
                        {
                            headPisitionQueue.Dequeue();
                        }
                        _lastUpdatePosTime = 0;
                    }

                    PosBean pr = headPisitionQueue.Peek();
                    while ((pr.time - _lastUpdatePosTime) < 0 && headPisitionQueue.Count() > 0)
                    {
                        Debug.Log("错误顺序 curTime:" + pr.time + " lastTime:" + _lastUpdatePosTime);
                        headPisitionQueue.Dequeue();
                        pr = headPisitionQueue.Peek();
                    }

                    if (_lastUpdatePosTime == 0)
                    {
                        _lastUpdatePosTime = pr.time - 0.04;
                    }
                    double curTime = TimeHelper.GetTimestamp();
                    if ((curTime - _lastUpdatePosLocalTime) > ((pr.time - _lastUpdatePosTime) - 10))
                    {
                        //  Debug.Log("VirtualManPlayer qeuelen:" + headPisitionQueue.Count() + " curTime:" + curTime + " prTime:" + pr.time
                        //   + " localLerp:" + (curTime - _lastUpdateTime) + " reomteLerp:" + (pr.time - _lastPosTime) + " curPos:" + head.position);
                        pr = headPisitionQueue.Dequeue();

                        if (Math.Abs(FF(_lastPos.x) - FF(pr.pos.x)) < 0.2 &&
                            Math.Abs(FF(_lastPos.y) - FF(pr.pos.y)) < 0.2 &&
                            Math.Abs(FF(_lastPos.z) - FF(pr.pos.z)) < 0.2)
                        {
                        }
                        else
                        {
                            iTween.MoveTo(gameObject, MrShareData._instance.RelativeTransform.TransformPoint(pr.pos),
                                          (float)(pr.time - _lastUpdatePosTime) / 1000);
                        }
                        _lastPos                = pr.pos;
                        _lastUpdatePosTime      = pr.time;
                        _lastUpdatePosLocalTime = curTime;
                    }
                }

                // 更新姿态
                if (headRotationQueue.Count() > 0)
                {
                    // 包过多则丢包
                    if (headRotationQueue.Count() > 60)
                    {
                        while (headRotationQueue.Count() > 5)
                        {
                            headRotationQueue.Dequeue();
                        }
                        _lastUpdateRotTime = 0;
                    }

                    RotBean r = headRotationQueue.Peek();
                    while ((r.time - _lastUpdateRotTime) < 0 && headRotationQueue.Count() > 0)
                    {
                        Debug.Log("错误顺序 curTime:" + r.time + " lastTime:" + _lastUpdateRotTime);
                        headRotationQueue.Dequeue();
                        r = headRotationQueue.Peek();
                    }

                    if (_lastUpdateRotTime == 0)
                    {
                        _lastUpdateRotTime = r.time - 0.04;
                    }
                    double curTime = TimeHelper.GetTimestamp();
                    if ((curTime - _lastUpdateRotLocalTime) > ((r.time - _lastUpdateRotTime) - 10))
                    {
                        r = headRotationQueue.Dequeue();

                        if (FFR(_lastRot.x) == FFR(r.rot.x) && FFR(_lastRot.y) == FFR(r.rot.y) && FFR(_lastRot.z) == FFR(r.rot.z))
                        {
                        }
                        else
                        {
                            head.localEulerAngles = r.rot;
                        }
                        _lastRot = r.rot;

                        _lastUpdateRotTime      = r.time;
                        _lastUpdateRotLocalTime = curTime;
                    }
                }
            }
        }
Пример #4
0
        void Update()
        {
            if (!IsLocolPlayer)
            {
                // 更新位置
                if (headPisitionQueue.Count() > 0)
                {
                    // 包过多则丢包
                    if (headPisitionQueue.Count() > 60)
                    {
                        while (headPisitionQueue.Count() > 5)
                        {
                            headPisitionQueue.Dequeue();
                        }
                        _lastUpdatePosTime = 0;
                    }

                    PosBean pr = headPisitionQueue.Peek();
                    while ((pr.time - _lastUpdatePosTime) < 0 && headPisitionQueue.Count() > 0)
                    {
                        Debug.Log("错误顺序 curTime:" + pr.time + " lastTime:" + _lastUpdatePosTime);
                        headPisitionQueue.Dequeue();
                        pr = headPisitionQueue.Peek();
                    }

                    if (_lastUpdatePosTime == 0)
                    {
                        _lastUpdatePosTime = pr.time - 0.04;
                    }
                    double curTime = TimeHelper.GetTimestamp();
                    if ((curTime - _lastUpdatePosLocalTime) > ((pr.time - _lastUpdatePosTime) - 10))
                    {
                        //  Debug.Log("VirtualManPlayer qeuelen:" + headPisitionQueue.Count() + " curTime:" + curTime + " prTime:" + pr.time
                        //   + " localLerp:" + (curTime - _lastUpdateTime) + " reomteLerp:" + (pr.time - _lastPosTime) + " curPos:" + head.position);
                        pr = headPisitionQueue.Dequeue();

                        Vector3 posHead = HoloWorldSync.Instance.WorldRoot.transform.TransformPoint(pr.pos);//MrShareData._instance.RelativeTransform.TransformPoint(pr.pos);
#if !UNITY_EDITOR && UNITY_IPHONE
                        posHead = new Vector3(posHead.x, MrShareData._instance.FloorY * 2, posHead.z);
#else
                        posHead = new Vector3(posHead.x, MrShareData._instance.FloorY, posHead.z);
#endif

                        iTween.MoveTo(head.gameObject, posHead, (float)(pr.time - _lastUpdatePosTime) / 1000);

                        body.localEulerAngles = new Vector3(0, head.localEulerAngles.y, 0);
#if !UNITY_EDITOR && UNITY_IPHONE
                        body.localPosition = new Vector3(head.localPosition.x, MrShareData._instance.FloorY * 2, head.localPosition.z);
#else
                        body.localPosition = new Vector3(head.localPosition.x, MrShareData._instance.FloorY, head.localPosition.z);
#endif
                        //                 Debug.Log ("VirtualManPlayer position:" + head.position.ToString() + " worldposition:" + HoloWorldSync.Instance.WorldRoot.transform.position.ToString() +
                        //" localScale:" + head.localScale.ToString() + " recvposition:" + pr.pos.ToString());

                        _lastPos                = pr.pos;
                        _lastUpdatePosTime      = pr.time;
                        _lastUpdatePosLocalTime = curTime;
                    }
                }

                // 更新姿态
                if (headRotationQueue.Count() > 0)
                {
                    // 包过多则丢包
                    if (headRotationQueue.Count() > 60)
                    {
                        while (headRotationQueue.Count() > 5)
                        {
                            headRotationQueue.Dequeue();
                        }
                        _lastUpdateRotTime = 0;
                    }

                    RotBean r = headRotationQueue.Peek();
                    while ((r.time - _lastUpdateRotTime) < 0 && headRotationQueue.Count() > 0)
                    {
                        Debug.Log("错误顺序 curTime:" + r.time + " lastTime:" + _lastUpdateRotTime);
                        headRotationQueue.Dequeue();
                        r = headRotationQueue.Peek();
                    }

                    if (_lastUpdateRotTime == 0)
                    {
                        _lastUpdateRotTime = r.time - 0.04;
                    }
                    double curTime = TimeHelper.GetTimestamp();
                    if ((curTime - _lastUpdateRotLocalTime) > ((r.time - _lastUpdateRotTime) - 10))
                    {
                        r = headRotationQueue.Dequeue();
                        head.localEulerAngles = r.rot;
                        body.localEulerAngles = new Vector3(0, head.localEulerAngles.y, 0);

                        _lastUpdateRotTime      = r.time;
                        _lastUpdateRotLocalTime = curTime;

                        //Debug.Log ("VirtualManPlayer localEulerAngles:" + head.localEulerAngles.ToString()
                        //	+ " body.localEulerAngles:" + body.localEulerAngles.ToString()
                        //	+ " recvrotation:" + r.rot.ToString());
                    }
                }

                // 更新动画
                if (animQueue.Count() > 0)
                {
                    AnimBean anim = animQueue.Dequeue();
                    VirtualManAnimatorChange(anim.animId);
                }
            }
            else
            {
                //走路动画

                if (canCheck)
                {
                    StartCoroutine(WalkCheck());
                }
            }
        }
Пример #5
0
        void Update()
        {
            if (Input.GetKey(KeyCode.B))
            {
                if (ShowLog._instance != null)
                {
                    ShowLog._instance.ShowHide();
                }
            }

            while (operationQueue.Count() > 0)
            {
                OperationBean op = operationQueue.Dequeue();
                switch (op.op)
                {
                case OperationBean.OpId.UserEnter:
                    PlayerUserIdList.Add((string)op.param);
                    ClientType clientType = UserIdUtil.GetClientTypeByUid((string)op.param);
                    #region  发送Creator的语言版本,每个客户端应自主选择
                    //if (GameLanguageController._instance.GameLanguageType == LanguageType.Chinese)
                    //{
                    //    SyncInterface.Instance.SyncOtherCmd("CmdSetLanguageCn", new string[0]);
                    //}
                    //else
                    //{
                    //    SyncInterface.Instance.SyncOtherCmd("CmdSetLanguageEn", new string[0]);
                    //}
                    //SyncInterface.Instance.SyncOtherCmd("CmdCloseLanguagePanel", new string[0]);
                    #endregion
                    if (clientType == ClientType.IOS)
                    {
                        //TODO-->>  IOS端登陆成功
                        //TODO-->>  隐藏hololens提示UI
                    }
                    if (clientType == ClientType.Hololens)
                    {
                        AddVirtualManPlayer((string)op.param, false, false);
                    }
                    break;

                case OperationBean.OpId.UserLeave:
                    if (PlayerUserIdList.Contains((string)op.param))
                    {
                        PlayerUserIdList.Remove((string)op.param);
                    }
                    RemoveVirtualManPlayer((string)op.param);
                    if (PlayerUserIdList.Count == 0)
                    {
                        Disconnect();
                    }
                    break;

                case OperationBean.OpId.SelfJoinRoom:
                    if (this.clientType != ClientType.SpectatorViewPc && this.clientType != ClientType.IOS)
                    {
                        AddVirtualManPlayer(this.mineUid, true, this.isControler);

                        SyncInterface.Instance.OnSelfJoinnedRoom(roomId, this.isCreator,
                                                                 (Dictionary <string, string[]>)op.param);
                    }

                    //OpenSyncWorldRootCanvas();
                    break;

                case OperationBean.OpId.NetDisconn:
                    if (MrShareData._instance.needLocated)
                    {
                        MrShareData._instance.needLocated = false;
                        MrShareData._instance.FloorTarget.SetActive(false);
                    }

                    ClearUserList();
                    PlayerUserIdList.Clear();
                    SetStates(VirtualManState.Init);
                    SyncInterface.Instance.OnSelfLeftRoom(roomId);

                    break;

                case OperationBean.OpId.FloorLocated:
                    if (state == VirtualManState.FloorLocating)
                    {
                        SetStates(VirtualManState.FloorLoacted);
                    }
                    else
                    {
                        Debug.Log("VM#OperationBean.OpId.FloorLocated#Wrong State. Current State:" +
                                  state.ToString());
                    }
                    break;

                case OperationBean.OpId.OtherCmd:
                    OtherCmd cmd = (OtherCmd)op.param;
                    SyncInterface.Instance.OnSyncOtherCmd(cmd.id, cmd.cmd);
                    break;

                case OperationBean.OpId.OnRoomCache:
                    SyncInterface.Instance.OnRoomCache(roomId, (Dictionary <string, string[]>)op.param);
                    break;
                }
            }
        }