コード例 #1
0
 public override void ReadAllData()
 {
     try{
         roleId = ReadInt();
         int x = ReadInt();
         int y = ReadInt();
         int z = ReadInt();
         pos    = new WorldPos(x, y, z);
         isExit = ReadBool();
         if (isExit)
         {
             compressType  = ReadByte();
             chunkByteData = ReadBytes();
         }
         hasChangedData = ReadBool();
         if (hasChangedData)
         {
             int sign = ReadInt();
             List <ClientChangedBlock> list = ReadListChangedBlockData();
             changedData = new ClientChangedChunkData(sign, list);
         }
     }catch (Exception e)
     {
         UnityEngine.Debug.LogError(e.StackTrace);
     }
 }
コード例 #2
0
        private void NetGeneratorWorker()
        {
            NetPriorityChunk netPriorityChunk = DeNetGeneratorQueue();

            if (netPriorityChunk != null)
            {
                Chunk chunk = netPriorityChunk.netChunk.chunk;
                if (!netPriorityChunk.netChunk.chunkData.isExist)
                {
                    WorldPos pos = chunk.worldPos;
                    if (World.world.GetChunk(pos.x, pos.y, pos.z) == null)
                    {
                        return;
                    }
                    if (!chunk.isTerrainDataPrepared)
                    {
                        _terrainControlGenerator.Generate(chunk);
                        if (WorldConfig.Instance.CaveEnable)
                        {
                            _cavesGenerator.generate(chunk);
                        }
                        chunk.isTerrainDataPrepared = true;
                        chunk.isUpdate = true;
                        //这里是地形数据在本机上产生时,需要发送到服务器上
                        EventManager.SendEvent(EventMacro.CHUNK_DATA_GENERATE_FINISH, chunk);
                    }
                }
                //如果服务器上已经有最新的数据,拿到最新的数据更改
                if (netPriorityChunk.netChunk.chunkData.hasChangeData)
                {
                    ClientChangedChunkData changedData = netPriorityChunk.netChunk.chunkData.changedData;
                    chunk.UpdateSign(changedData.sign);
                    if (changedData.list.Count > 0)
                    {
                        for (int i = 0; i < changedData.list.Count; i++)
                        {
                            ClientChangedBlock changedBlock = changedData.list[i];
                            chunk.UpdateClientChangedBlock(changedBlock);
                        }
                        ReculateChunkLightAndAround(chunk);
                    }
                }
                CheckAroundChunkAndGeneratorPopulation(chunk, true);
            }

            ////////////////////////////////////////////////////
            //收到服务器同步的大块更改数据
            refreshNetArea();
        }
コード例 #3
0
        public override void ServerDo(ClientConnectionWorker connectionWork)
        {
            ClientPlayer           player = NetManager.Instance.server.playerManager.GetPlayer(roleId);
            ClientChangedChunkData data   = NetManager.Instance.server.sceneManager.GetChangedChunkData(pos);

            if (data != null)
            {
                hasChangedData = true;
                changedData    = data;
            }
            if (player != null)
            {
                player.worker.SendPackage(this);
            }
        }
コード例 #4
0
        public override void ServerDo(ClientConnectionWorker connectionWork)
        {
            ClientPlayer mainPlayer = NetManager.Instance.server.playerManager.mainPlayer;

            if (mainPlayer.id == roleId)
            {
                ResponseChunkPackage package = PackageFactory.GetPackage(PackageType.ResponseChunk) as ResponseChunkPackage;
                package.roleId = roleId;
                package.pos    = pos;
                package.isExit = false;
                ClientChangedChunkData data = NetManager.Instance.server.sceneManager.GetChangedChunkData(pos);
                if (data != null)
                {
                    package.hasChangedData = true;
                    package.changedData    = data;
                }
                mainPlayer.worker.SendPackage(package);
            }
            else
            {
                mainPlayer.worker.SendPackage(this);
            }
        }