示例#1
0
    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);
    }
示例#2
0
    public static void ChunksEnterLeaveViewReq(List <Vector2Int> enterViewChunks, List <Vector2Int> leaveViewChunks = null)
    {
        CSChunksEnterLeaveViewReq req = new CSChunksEnterLeaveViewReq();

        List <CSVector2Int> enter = new List <CSVector2Int>();

        foreach (Vector2Int chunk in enterViewChunks)
        {
            CSVector2Int c = new CSVector2Int
            {
                x = chunk.x,
                y = chunk.y
            };
            enter.Add(c);
        }
        req.EnterViewChunks.AddRange(enter);

        if (leaveViewChunks != null)
        {
            List <CSVector2Int> leave = new List <CSVector2Int>();
            foreach (Vector2Int chunk in leaveViewChunks)
            {
                CSVector2Int c = new CSVector2Int
                {
                    x = chunk.x,
                    y = chunk.y
                };
                leave.Add(c);
            }
            req.LeaveViewChunks.AddRange(leave);
        }

        //Debug.Log("CS_CHUNKS_ENTER_LEVAE_VIEW_REQ," + req.EnterViewChunks.Count + "," + req.LeaveViewChunks.Count);
        NetworkManager.SendPkgToServer(ENUM_CMD.CS_CHUNKS_ENTER_LEVAE_VIEW_REQ, req, ChunksEnterLeaveViewRes);
    }
示例#3
0
        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);
            }
        }