public void CreateJoinRoom(EnterRoomData roomData) { Debug.Log("GameRoomManager CreateJoinRoom() Begin..."); if (roomData.IsCreatingRoom) {// 创建房间流程 Log($"MSG: CreateJoinRoom - 创建房间:{roomData.RoomName}"); // 把地图数据上传到房间服务器保存。后面的和加入房间一样了。 BinaryReader reader = HexmapHelper.BeginLoadBuffer(roomData.RoomName); if (reader != null) { const int CHUNK_SIZE = 900; byte[] bytes = new byte[CHUNK_SIZE]; int size = CHUNK_SIZE; bool isFileEnd = false; int index = 0; while (!isFileEnd) { if (!HexmapHelper.LoadBuffer(reader, out bytes, ref size, ref isFileEnd)) { Log($"Load Buffer Failed - {roomData.RoomName}"); } UploadMap output = new UploadMap() { RoomName = roomData.RoomName, MaxPlayerCount = roomData.MaxPlayerCount, MapData = ByteString.CopyFrom(bytes), PackageIndex = index++, IsLastPackage = isFileEnd, }; SendMsg(ROOM.UploadMap, output.ToByteArray()); } Log($"MSG: 发送地图数据 - 地图名:{roomData.RoomName} - Total Size:{reader.BaseStream.Length}"); HexmapHelper.EndLoadBuffer(ref reader); } } else {// 直接申请进入房间 // 发出EnterRoom消息,进入房间 EnterRoom output = new EnterRoom() { RoomId = roomData.RoomId, }; SendMsg(ROOM.EnterRoom, output.ToByteArray()); Log($"MSG: CreateJoinRoom - 申请进入房间:{roomData.RoomName}"); } }
private static void UPLOAD_MAP_REPLY(byte[] bytes) { UploadMapReply input = UploadMapReply.Parser.ParseFrom(bytes); if (!input.Ret) { string msg = "上传地图失败!"; UIManager.Instance.SystemTips(msg, PanelSystemTips.MessageType.Error); GameRoomManager.Instance.Log("MSG: UPLOAD_MAP_REPLY Error - " + msg); return; } if (input.IsLastPackage) { GameRoomManager.Instance.Log($"MSG: UPLOAD_MAP_REPLY OK - 上传地图成功!RoomID:{input.RoomId}"); // 发出EnterRoom消息,进入房间 EnterRoom output = new EnterRoom() { RoomId = input.RoomId, }; GameRoomManager.Instance.SendMsg(ROOM.EnterRoom, output.ToByteArray()); GameRoomManager.Instance.Log($"MSG: UPLOAD_MAP_REPLY OK - 申请进入战场:{input.RoomName}"); } }