/// <summary> /// 同步其他类型命令 /// </summary> /// <param name="id"></param> /// <param name="param"></param> public void SyncOtherCmd(string id, string param) { string rid; MqttHelper mqttHelper = ChooseMqtt(SyncType.Other, out rid); if (mqttHelper == null) { return; } OtherCmd otherCmd = new OtherCmd(); otherCmd.id = id; otherCmd.cmd = param; byte[] cmd = EncodeStruct <OtherCmd>(otherCmd); SendCmdMessage(mqttHelper, rid, NetCmdIdClient.OtherCmd, cmd); }
private void NetWork_onReceiveCmd(string rid, NetCmdIdClient cid, object cmd) { if (rid != null && rid.Equals(this.roomId)) { switch (cid) { case NetCmdIdClient.None: break; case NetCmdIdClient.AnchorUploaded: { if (clientType != ClientType.SpectatorViewPc && clientType != ClientType.IOS) { AnchorUploaded clientCmd = (AnchorUploaded)cmd; this.anchorName = clientCmd.anchor; OperationBean oper = new OperationBean(); oper.op = OperationBean.OpId.DownAnchor; oper.param = anchorName; operationQueue.Enqueue(oper); } } break; case NetCmdIdClient.TakeControlPower: { //TakeControlPower clientCmd = (TakeControlPower)cmd; } break; case NetCmdIdClient.SyncPos: { SyncPos clientCmd = (SyncPos)cmd; if (clientCmd.type == SyncType.VirtualMan) { if (PlayerUserList.ContainsKey(clientCmd.id)) { SpectatorViewPlayer player; PlayerUserList.TryGetValue(clientCmd.id, out player); if (player) { player.OnRecvPosition(new Vector3(clientCmd.px, clientCmd.py, clientCmd.pz), clientCmd.time); } } } } break; case NetCmdIdClient.SyncRotate: { SyncRotate clientCmd = (SyncRotate)cmd; if (clientCmd.type == SyncType.VirtualMan) { if (PlayerUserList.ContainsKey(clientCmd.id)) { SpectatorViewPlayer player; PlayerUserList.TryGetValue(clientCmd.id, out player); if (player) { player.OnRecvRotation(new Vector3(clientCmd.rx, clientCmd.ry, clientCmd.rz), clientCmd.time); } } } } break; case NetCmdIdClient.SyncAnim: { SyncAnim clientCmd = (SyncAnim)cmd; if (clientCmd.type == SyncType.SpectatorView) { } } break; case NetCmdIdClient.OtherCmd: { OtherCmd clientCmd = (OtherCmd)cmd; OperationBean op = new OperationBean(); op.op = OperationBean.OpId.OtherCmd; op.param = clientCmd; operationQueue.Enqueue(op); } break; case NetCmdIdClient.FloorLocated: { FloorLocated clientCmd = (FloorLocated)cmd; _lerpStageWithFloor = clientCmd.y; Vector3 v = new Vector3(clientCmd.x, clientCmd.y, clientCmd.z); //TODO---->>>> GeMesCar测试数据 //ipad if (clientType == ClientType.IOS) { OperationBean op = new OperationBean(); op.op = OperationBean.OpId.ios_AdjustFloorLocate; op.param = v; operationQueue.Enqueue(op); } else { OperationBean op = new OperationBean(); op.op = OperationBean.OpId.hololens_AdjustFloorLocate; op.param = v; operationQueue.Enqueue(op); } Debug.Log("收到creater定位地面的消息-->>>>> " + v.ToString()); } break; case NetCmdIdClient.MarkerGenerated: { OperationBean op = new OperationBean(); op.op = OperationBean.OpId.MarkerGenerated; op.param = cmd; operationQueue.Enqueue(op); } break; case NetCmdIdClient.MarkerDetected: { OperationBean op = new OperationBean(); op.op = OperationBean.OpId.MarkerDetected; op.param = cmd; operationQueue.Enqueue(op); } break; case NetCmdIdClient.SyncWorldRoot: { Debug.Log("SpectatorViewManager#NetWork_onReceiveCmd#SyncWorldRoot"); OperationBean op = new OperationBean(); op.op = OperationBean.OpId.SyncWorldRoot; op.param = cmd; operationQueue.Enqueue(op); } break; } } }
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 (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; } } }
private void NetWork_onReceiveCmd(string rid, NetCmdIdClient cid, object cmd) { if (rid != null && rid.Equals(this.roomId)) { switch (cid) { case NetCmdIdClient.None: break; case NetCmdIdClient.AnchorUploaded: { //AnchorUploaded clientCmd = (AnchorUploaded)cmd; } break; case NetCmdIdClient.TakeControlPower: { //TakeControlPower clientCmd = (TakeControlPower)cmd; isControler = false; } break; case NetCmdIdClient.SyncPos: { SyncPos clientCmd = (SyncPos)cmd; if (clientCmd.type == SyncType.VirtualMan) { if (PlayerUserList.ContainsKey(clientCmd.id)) { VirtualManPlayer player; PlayerUserList.TryGetValue(clientCmd.id, out player); if (player) { player.OnRecvPosition(new Vector3(clientCmd.px, clientCmd.py, clientCmd.pz), clientCmd.time); } } } } break; case NetCmdIdClient.SyncRotate: { SyncRotate clientCmd = (SyncRotate)cmd; if (clientCmd.type == SyncType.VirtualMan) { if (PlayerUserList.ContainsKey(clientCmd.id)) { VirtualManPlayer player; PlayerUserList.TryGetValue(clientCmd.id, out player); if (player) { player.OnRecvRotation(new Vector3(clientCmd.rx, clientCmd.ry, clientCmd.rz), clientCmd.time); } } } } break; case NetCmdIdClient.SyncAnim: { SyncAnim clientCmd = (SyncAnim)cmd; if (clientCmd.type == SyncType.VirtualMan) { if (PlayerUserList.ContainsKey(clientCmd.id)) { VirtualManPlayer player; PlayerUserList.TryGetValue(clientCmd.id, out player); if (player) { player.onRecvAnimation(clientCmd.amimid, clientCmd.time); } } } } break; case NetCmdIdClient.OtherCmd: { OtherCmd clientCmd = (OtherCmd)cmd; OperationBean op = new OperationBean(); op.op = OperationBean.OpId.OtherCmd; op.param = clientCmd; operationQueue.Enqueue(op); } break; } } }