public static void SendAudioMessage(byte [] data) { AudioChatMsg msg = new AudioChatMsg(); msg.type = 0; msg.audio_data = data; msg.playerId = (uint)Main.Ins.NetWorkBattle.PlayerId; Exec(TcpClientProxy.sProxy, (int)MeteorMsg.MsgType.AudioChat, msg); }
//套接口消息. public static void Update() { //处理网络消息 for (int i = 0; i < packets.Count; i++) { Dictionary <int, byte[]> pack = packets[i]; lock (pack) { MemoryStream ms = null; try { foreach (var each in pack) { //UnityEngine.Debug.LogError(string.Format("收到:{0}", each.Key)); switch (each.Key) { case (int)MeteorMsg.MsgType.ProtocolVerifyRsp: ms = new MemoryStream(each.Value); ProtocolVerifyRsp rspVer = ProtoBuf.Serializer.Deserialize <ProtocolVerifyRsp>(ms); OnVerifyResult(rspVer); break; case (int)MeteorMsg.MsgType.GetRoomRsp: ms = new MemoryStream(each.Value); GetRoomRsp rspG = ProtoBuf.Serializer.Deserialize <GetRoomRsp>(ms); OnGetRoomRsp(rspG); break; case (int)MeteorMsg.MsgType.JoinRoomRsp: ms = new MemoryStream(each.Value); JoinRoomRsp rspJ = ProtoBuf.Serializer.Deserialize <JoinRoomRsp>(ms); ClientJoinRoomRsp(rspJ); break; //case (int)MeteorMsg.MsgType.OnJoinRoomRsp: // ms = new MemoryStream(each.Value); // OnEnterRoomRsp rspE = ProtoBuf.Serializer.Deserialize<OnEnterRoomRsp>(ms); // OnEnterRoomRsp_(rspE); // break; case (int)MeteorMsg.MsgType.CreateRoomRsp: ms = new MemoryStream(each.Value); CreateRoomRsp rspC = ProtoBuf.Serializer.Deserialize <CreateRoomRsp>(ms); OnCreateRoomRsp(rspC); break; //case (int)MeteorMsg.MsgType.EnterLevelRsp: // ms = new MemoryStream(each.Value); // EnterLevelRsp rspER = ProtoBuf.Serializer.Deserialize<EnterLevelRsp>(ms); // EnterLevelRsp_(rspER); // break; //case (int)MeteorMsg.MsgType.OnEnterLevelRsp: // ms = new MemoryStream(each.Value); // OnEnterLevelRsp rspOE = ProtoBuf.Serializer.Deserialize<OnEnterLevelRsp>(ms); // OnEnterLevelRsp_(rspOE); // break; //case (int)MeteorMsg.MsgType.UserRebornSB2C: // ms = new MemoryStream(each.Value); // OnEnterLevelRsp rspReborn = ProtoBuf.Serializer.Deserialize<OnEnterLevelRsp>(ms); // OnUserRebornRsp_(rspReborn); // break; //case (int)MeteorMsg.MsgType.OnLeaveRoomRsp: // ms = new MemoryStream(each.Value); // OnLeaveRoomRsp rspL = ProtoBuf.Serializer.Deserialize<OnLeaveRoomRsp>(ms); // OnLeaveRoomRsp_(rspL); // break; case (int)MeteorMsg.MsgType.ChatInRoomRsp: ms = new MemoryStream(each.Value); ChatMsg chatRsp = ProtoBuf.Serializer.Deserialize <ChatMsg>(ms); OnReceiveChatMsg(chatRsp); break; case (int)MeteorMsg.MsgType.AudioChat: ms = new MemoryStream(each.Value); AudioChatMsg audioRsp = ProtoBuf.Serializer.Deserialize <AudioChatMsg>(ms); OnReceiveAudioMsg(audioRsp); break; //case (int)MeteorMsg.MsgType.UserDeadSB2C: // //Debug.LogError("OnUserDead"); // ms = new MemoryStream(each.Value); // UserId userDeadRsp = ProtoBuf.Serializer.Deserialize<UserId>(ms); // OnUserDead(userDeadRsp); // break; //case (int)MeteorMsg.MsgType.ExitQueueRsp: // OnExitQueue(); // break; case (int)MeteorMsg.MsgType.EnterQueueRsp: OnEnterQueue(); break; //帧同步信息-UDP //收到服务器的帧同步信息. case (int)MeteorMsg.MsgType.SyncCommand: ms = new MemoryStream(each.Value); GameFrames t = ProtoBuf.Serializer.Deserialize <GameFrames>(ms); Main.Ins.FrameSync.OnReceiveCommand(t); break; } } } catch (Exception exp) { UnityEngine.Debug.LogError(exp.Message + exp.StackTrace); } finally { pack.Clear(); } } } lock (messageQueue) { int length = messageQueue.Count; for (int i = 0; i < length; i++) { switch (messageQueue[i].Message) { case (short)LocalMsgType.Connect: OnConnect(messageQueue[i].Result, messageQueue[i].message); break; case (short)LocalMsgType.DisConnect: OnDisconnect(); break; case (short)LocalMsgType.SendFTPLogComplete: OnSendComplete(messageQueue[i].Result, messageQueue[i].Param); break; case (short)LocalMsgType.GameStart: OnGameStart(); break; case (short)LocalMsgType.SaveRecord: OnSaveRecord(messageQueue[i]); break; case (short)LocalMsgType.PathCalcFinished: OnPathCalcFinished(messageQueue[i]); break; } } messageQueue.Clear(); } }
//某人发来一段语音,显示一个按钮,点击了就播放这段语音即可. static void OnReceiveAudioMsg(AudioChatMsg msg) { //if (!RoomChatWnd.Exist) // RoomChatWnd.Instance.Open(); //RoomChatWnd.Instance.Add((int)msg.playerId, msg.audio_data); }