From 771b15d4fff6bd9a97a2f3287470fa74d9f4517a Mon Sep 17 00:00:00 2001 From: huyulong <1838407198@qq.com> Date: Sun, 29 Dec 2024 14:19:18 +0800 Subject: [PATCH] =?UTF-8?q?protobuf=E6=96=87=E4=BB=B6=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaofang/Assets/ProtoBuf/test.cs | 133 ++++++++++++++++++++++------ xiaofang/Assets/Scenes/Tmap 1.unity | 4 +- 2 files changed, 107 insertions(+), 30 deletions(-) diff --git a/xiaofang/Assets/ProtoBuf/test.cs b/xiaofang/Assets/ProtoBuf/test.cs index c855a2e8..062275ff 100644 --- a/xiaofang/Assets/ProtoBuf/test.cs +++ b/xiaofang/Assets/ProtoBuf/test.cs @@ -108,8 +108,8 @@ public class test : MonoBehaviour Debug.Log("每秒执行一次"); wEBScriptListener.SendMessageByte(sendData); - // 等待一秒 - await Task.Delay(1000); + // 等待2秒 + await Task.Delay(2000); } } //帧存储操作输入 @@ -251,13 +251,13 @@ public class test : MonoBehaviour } //推送npc和玩家的信息 - void Location(string userId = "2",string roomId = "3") + void Location(string userId = "2", string roomId = "3") { MoveResponse data = new MoveResponse(); data.RoomId = roomId; data.UserId = userId; - + WSMessage msg = new WSMessage(); msg.Module = "move"; @@ -314,13 +314,13 @@ public class test : MonoBehaviour } //NPC路线选择 - public void NpcMove(string roomId = "1",int moveType = 2, int selectId = 3) + public void NpcMove(string roomId = "1", int moveType = 2, int selectId = 3) { MoveRequest data = new MoveRequest(); data.RoomId = roomId; data.MoveType = moveType; data.SelectId = selectId; - + WSMessage msg = new WSMessage(); msg.Module = "move"; msg.ServiceName = "MoveNpc"; @@ -383,7 +383,7 @@ public class test : MonoBehaviour data.ChannelName = "2"; data.ChannelType = "5"; data.Role = "6"; - + WSMessage msg = new WSMessage(); msg.Module = "voice"; msg.ServiceName = "RtcTokenHandler"; @@ -440,9 +440,9 @@ public class test : MonoBehaviour //BroadcastFrameMsg.FramesFieldNumber wEBScriptListener.SendMessageByte(sendData); - } - - + } + + // public void GetSelectHistoryList() { @@ -450,7 +450,7 @@ public class test : MonoBehaviour data.SelectId = "1"; data.UserId = "2"; data.RoomId = "3"; - + WSMessage msg = new WSMessage(); @@ -464,15 +464,15 @@ public class test : MonoBehaviour //BroadcastFrameMsg.FramesFieldNumber wEBScriptListener.SendMessageByte(sendData); - } - + } + // - public void GetTaskList(string userID,string roomID) + public void GetTaskList(string userID, string roomID) { TaskTrigger data = new TaskTrigger(); data.UserId = "2"; data.RoomId = "3"; - + WSMessage msg = new WSMessage(); @@ -486,8 +486,8 @@ public class test : MonoBehaviour //BroadcastFrameMsg.FramesFieldNumber wEBScriptListener.SendMessageByte(sendData); - } - + } + //推送玩家信息 public void ThatUser(PlayerJoinResponse player) { @@ -506,7 +506,7 @@ public class test : MonoBehaviour //BroadcastFrameMsg.FramesFieldNumber wEBScriptListener.SendMessageByte(sendData); - } + } public void TriggerNpcArrive() { MoveRoomAoiRequest data = new MoveRoomAoiRequest(); @@ -531,7 +531,11 @@ public class test : MonoBehaviour //BroadcastFrameMsg.FramesFieldNumber wEBScriptListener.SendMessageByte(sendData); - } + } + + + + // Start is called before the first frame update @@ -647,11 +651,26 @@ public class test : MonoBehaviour //广播 case "hall.BroadcastMessage": UserJoinResponse userJoinResponse = ProtoBufffer.DeSerialize(bytes); - - - - //Debug.Log(userJoinResponse.IncidentPosition); - Debug.Log(userJoinResponse); + /* + 这里是userJoinResponse带的数据信息 + int64 userId =1;//用户id + string nickName=2;//用户名 + string roleName=3;//用户角色 + string roomId=4;//房间号 + bool online =5;//状态 接收这个用户是不是掉线了 + 事件状态 1 用户上线 2用户下线 3 用户加入房间 4 事故发生 5 火势6 任务7 对象操作 8 NPc 属性更新 9 语音信息、 10 用户信息更新 11 房间开始 + int32 messageType = 6; + string cmd =7;//操作指令 + string incidentPosition=8://事件发生位置 + float fireRadius =9;//火势半径 + int32 firevalue = 10;//火势值 + TaskInfoResponse taskResponse=11;//任务信息 + 0bjectInfoResponse objectResponse=12;//对象信息 + NpcInfoResponse npcResponse=13;//npc信息 + VoiceTransportResponse voiceResponse =14;//语音信息 + PlayerJoinResponse playerResponse=15;//玩家信息 + */ + //Debug.Log(userJoinResponse); if (userJoinResponse.MessageType == 1)//用户上线 { Debug.Log("玩家:" + userJoinResponse.NickName + "上线"); @@ -670,16 +689,74 @@ public class test : MonoBehaviour } if (userJoinResponse.MessageType == 5)//火势 { + //这里写更新火势的信息 半径userJoinResponse.FireRadius 位置userJoinResponse.IncidentPosition 火势值userJoinResponse.FireValue + } if (userJoinResponse.MessageType == 6)//任务 { + //解析出任务信息到taskInfoResponse 里面有TaskId 状态Status 房间id 坐标x,y,z 类型Type 时间限制Timelimit 描述Des 触发条件Trigger 下一步任务NextTask 目标类型TargetType 奖励Reward 备注Note 创建时间CreatTime 更新时间UpdateTime 目标用户id ToUserId 基础任务的id BaseTaskid TaskInfoResponse taskInfoResponse = userJoinResponse.TaskResponse; if (long.Parse(taskInfoResponse.ToUserId) == userJoinResponse.UserId)//当这个任务是当前玩家的任务时显示任务 { TaskPanel.instance.Taskad(int.Parse(taskInfoResponse.TaskId)); } } + if (userJoinResponse.MessageType == 7)//对象操作 + { + //解析出的对象信息objectInfoResponse里面有 + /* + string RoomId=1;//对象id + string Id=2://ID + string objectId=3;//对象ID + string Note =4;//状态 + string Type =5;// 对象类型lilubing,2024/11/2716:37·对象物体及任务:Changes + + + string Name=6;//对象文本Id + int64 Nameshowoffset=7;//对象文本显示偏移量 + int64 showRadius=8;//对象显示半径 + string Icon =9;//对象图标 + string Role =10;//对象角色 + string ItemDepend =11;//依赖物品 + int64 Takerime = 12;// 交互、读条时间 -1 立即执行 + string Needplayers = 13;// 判定范围,玩家数量,是否可操作(当人数不满足时) + string Taskstatus=14;//对应事件ID + string selectList=15;//选择列表 + int64 onoff =16;// 操作状态 0不可操作1 可操作 + + string status=17;//状态 + string ResChange =18;//资源变化 + + int64 ParallelControl=19;//是否支持多人操作 + string ExtraValue=20;//额外参数 + string UserIds = 21;// 玩家id列表 逗号分隔 + + string Createrime =22;//创建时间 + + string Updaterime =23;//更新时间 + + */ + ObjectInfoResponse objectInfoResponse = userJoinResponse.ObjectResponse; + } + if (userJoinResponse.MessageType == 8)//NPC属性更新 + { + + } + if (userJoinResponse.MessageType == 9)//语音信息 + { + //解析出的语音信息voiceTransportResponse里面有 应用id AppId 用户id channelName + VoiceTransportResponse voiceTransportResponse = userJoinResponse.VoiceResponse; + } + if (userJoinResponse.MessageType == 10)//用户信息更新 + { + // + + } + if (userJoinResponse.MessageType == 11)//房间开始 + { + + } break; @@ -718,7 +795,7 @@ public class test : MonoBehaviour Vector3 position = new Vector3(x, y, z); NPCController.instance.InitNPC(position, npcData); - + } if (npcData.Type == 2)//npc移动 { @@ -745,7 +822,7 @@ public class test : MonoBehaviour Debug.Log($"NPCID{npcData.UserId}NPCPOSITION{v}"); } - + } } } @@ -815,7 +892,7 @@ public class test : MonoBehaviour case "hall.GetTaskList": Debug.Log("-----------move.MoveNpc"); TaskListResponse TaskListResponse = ProtoBufffer.DeSerialize(bytes); - foreach(var task in TaskListResponse.Tasks) + foreach (var task in TaskListResponse.Tasks) { Debug.Log(task.TaskId); } @@ -833,7 +910,7 @@ public class test : MonoBehaviour case "select.GetSelectHistoryList": Debug.Log("select.GetSelectHistoryList"); SelectHistoryResponse selectHistoryResponse = ProtoBufffer.DeSerialize(bytes); - foreach(var selectRes in selectHistoryResponse.Selects) + foreach (var selectRes in selectHistoryResponse.Selects) { Debug.Log(selectRes.Id); } diff --git a/xiaofang/Assets/Scenes/Tmap 1.unity b/xiaofang/Assets/Scenes/Tmap 1.unity index 1203801f..6de7169a 100644 --- a/xiaofang/Assets/Scenes/Tmap 1.unity +++ b/xiaofang/Assets/Scenes/Tmap 1.unity @@ -29321,7 +29321,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!81 &1707678917 AudioListener: m_ObjectHideFlags: 0 @@ -31410,7 +31410,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 43 + m_RootOrder: 44 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &1845569623 PrefabInstance: