Пример #1
0
        public static void OnDeleteBlockReq(Player player, MemoryStream stream)
        {
            Ultilities.Print("OnDeleteBlockReq");
            CSDeleteBlockReq req = NetworkManager.Deserialize <CSDeleteBlockReq>(stream);

            Vector2Int chunk   = Ultilities.GetChunk(req.position);
            bool       deleted = TerrainData.RemoveBlockInChunk(chunk, req.position);

            CSDeleteBlockRes res = new CSDeleteBlockRes();

            if (deleted)
            {
                res.RetCode  = 0;
                res.position = req.position;
            }
            else
            {
                res.RetCode = 3;
            }
            NetworkManager.Enqueue(player.socket, ENUM_CMD.CS_DELETE_BLOCK_RES, res);
            if (deleted)
            {
                //同步给有该chunk视野的其他玩家
                foreach (Player p in TerrainData.GetChunkViewPlayers(chunk))
                {
                    if (p.id != player.id)
                    {
                        DeleteBlockNotify(p, req.position);
                    }
                }
            }
        }
Пример #2
0
        public static void OnAddBlockReq(Player player, MemoryStream stream)
        {
            Ultilities.Print("OnAddBlockReq");
            CSAddBlockReq req = NetworkManager.Deserialize <CSAddBlockReq>(stream);

            Vector2Int chunk      = Ultilities.GetChunk(req.block.position);
            bool       addSuccess = TerrainData.AddBlockInChunk(chunk, req.block);

            //回包
            CSAddBlockRes res = new CSAddBlockRes();

            if (addSuccess)
            {
                res.RetCode = 0;
                res.block   = req.block;
            }
            else
            {
                res.RetCode = 2;
            }
            NetworkManager.Enqueue(player.socket, ENUM_CMD.CS_ADD_BLOCK_RES, res);
            if (addSuccess)
            {
                //同步给有该chunk视野的其他玩家
                foreach (Player p in TerrainData.GetChunkViewPlayers(chunk))
                {
                    if (p.id != player.id)
                    {
                        AddBlockNotify(p, req.block);
                    }
                }
            }
        }