Exemple #1
0
 private IEnumerator RefreshEntity()
 {
     while (true)
     {
         if (world.FirstGeneted)
         {
             if (entityRefreshQueue.Count > 0)
             {
                 WorldPos refreshPos = entityRefreshQueue.Dequeue();
                 //真正要刷的时候再次判断是否在玩家视野
                 if (IsInPlayerView(refreshPos))
                 {
                     Chunk chunk = world.GetChunk(refreshPos.x, refreshPos.y, refreshPos.z);
                     if (chunk != null && chunk.isGenerated && !chunk.hasRefreshEntities)
                     {
                         //向服务器发送刷新怪物请求
                         List <EntityData> list = chunk.ClearEntityAndSetRefresh();
                         RequestRefreshChunkEntitiesPackage package = PackageFactory.GetPackage(PackageType.RequestRefreshChunkEntities)
                                                                      as RequestRefreshChunkEntitiesPackage;
                         package.entities = list;
                         package.pos      = chunk.worldPos;
                         NetManager.Instance.client.SendPackage(package);
                     }
                 }
             }
         }
         yield return(null);
     }
 }