static void Single_OnChunksEnterLeaveViewReq(object obj, Action <object> callback) { CSChunksEnterLeaveViewReq req = obj as CSChunksEnterLeaveViewReq; CSChunksEnterLeaveViewRes res = new CSChunksEnterLeaveViewRes(); res.RetCode = 0; foreach (CSVector2Int chunk in req.EnterViewChunks) { Vector2Int chunkPos = chunk.ToVector2Int(); byte[] blocks = GetChunkData(chunkPos); if (!chunkGenerateFlagSet.Contains(chunkPos)) { TerrainGenerator.GenerateChunkData(chunk, blocks); chunkGenerateFlagSet.Add(chunkPos); } CSChunk c = new CSChunk(); c.Position = chunk; c.BlocksInBytes = (byte[])blocks.Clone(); res.EnterViewChunks.Add(c); } foreach (CSVector2Int chunk in req.LeaveViewChunks) { res.LeaveViewChunks.Add(chunk); } callback(res); }
static void ChunksEnterLeaveViewRes(object data) { CSChunksEnterLeaveViewRes rsp = NetworkManager.Deserialize <CSChunksEnterLeaveViewRes>(data); //Debug.Log("CSChunksEnterLeaveViewRes," + rsp.EnterViewChunks.Count + "," + rsp.LeaveViewChunks.Count); if (rsp.RetCode == 0) { foreach (CSVector2Int csv in rsp.LeaveViewChunks) { UnloadChunk(csv.x, csv.y); } foreach (CSChunk cschunk in rsp.EnterViewChunks) { LoadChunk(cschunk); } if (!PlayerController.isInitialized) { PlayerController.Init(); LocalNavMeshBuilder.Init(); ChunkRefresher.ForceRefreshAll(); } ChunkChecker.FinishRefresh(); } else { FastTips.Show(rsp.RetCode); } }
public static void OnChunksEnterLeaveViewReq(Player player, MemoryStream stream) { CSChunksEnterLeaveViewReq req = NetworkManager.Deserialize <CSChunksEnterLeaveViewReq>(stream); Ultilities.Print("CSChunksEnterLeaveViewReq," + req.EnterViewChunks.Count + "," + req.LeaveViewChunks.Count); bool leaveView = true; bool enterView = ProcessChunksEnterView(player, req.EnterViewChunks, out List <CSChunk> enterViewChunks); List <Vector2Int> leaveViewChunks = null; if (enterView) { if (req.LeaveViewChunks.Count > 0) { leaveView = ProcessChunksLeaveView(player, req.LeaveViewChunks, out leaveViewChunks); } } if (enterView && leaveView) { CSChunksEnterLeaveViewRes res = new CSChunksEnterLeaveViewRes { RetCode = 0 }; res.EnterViewChunks.AddRange(enterViewChunks); if (leaveViewChunks != null) { res.LeaveViewChunks.AddRange(Vector2Int.Vector2IntList_To_CSVector2IntList(leaveViewChunks)); } Ultilities.Print("CSChunksEnterLeaveViewRes," + res.EnterViewChunks.Count + "," + res.LeaveViewChunks.Count); NetworkManager.Enqueue(player.socket, ENUM_CMD.CS_CHUNKS_ENTER_LEAVE_VIEW_RES, res); } else { CSChunksEnterLeaveViewRes res = new CSChunksEnterLeaveViewRes { RetCode = 4 }; Ultilities.Print("CSChunksEnterLeaveViewRes," + res.EnterViewChunks.Count + "," + res.LeaveViewChunks.Count); NetworkManager.Enqueue(player.socket, ENUM_CMD.CS_CHUNKS_ENTER_LEAVE_VIEW_RES, res); } }