/// <summary> /// 同步位置 /// </summary> /// <param name="targetId">目标id</param> /// <param name="type">同步类型</param> /// <param name="objId">对象id</param> /// <param name="position">位置</param> public void SyncPosition(string targetId, SyncType type, string objId, Vector3 position) { string rid; MqttHelper mqttHelper = ChooseMqtt(type, out rid); if (mqttHelper == null) { return; } SyncPos headPos = new SyncPos(); headPos.type = type; headPos.id = objId; headPos.px = position.x; headPos.py = position.y; headPos.pz = position.z; headPos.time = TimeHelper.GetTimestamp(); //Debug.Log("SyncPosition type:" + type + "objid:" + objId + " pos:" + position + " time:" + headPos.time); if (_lastPosTime >= headPos.time) { //Debug.Log("SyncPosition 顺序错误 cur:" + headPos.time + " last:" + _lastPosTime); } _lastPosTime = headPos.time; byte[] cmd = EncodeStruct <SyncPos>(headPos); if (targetId == null) { SendCmdMessage(mqttHelper, rid, NetCmdIdClient.SyncPos, cmd); } else { SendCmdMessage(mqttHelper, targetId, NetCmdIdClient.SyncPos, 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; } } }
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; } } }