Пример #1
0
 void Update()
 {
     for (float x = transform.position.x - viewRange; x < transform.position.x + viewRange; x += chunkWidth)
     {
         for (float z = transform.position.z - viewRange; z < transform.position.z + viewRange; z += chunkWidth)
         {
             Vector3 pos = new Vector3(x, 0, z);
             pos.x = Mathf.Floor(pos.x / (float)chunkWidth) * chunkWidth;
             pos.z = Mathf.Floor(pos.z / (float)chunkWidth) * chunkWidth;
             Chunk chunk = Chunk.FindChunk(pos);
             if (chunk != null)
             {
                 continue;
             }
             if (Vector3.Distance(pos, transform.position) < viewRange)
             {
                 chunk = (Chunk)Instantiate(chunkFab, pos, Quaternion.identity);
             }
         }
     }
 }
Пример #2
0
 public virtual byte GetByte(int x, int y, int z)
 {
     if ((y < 0) || (y >= height))
     {
         return(0);
     }
     if ((x < 0) || (z < 0) || (x >= width) || (z >= width))
     {
         Vector3 worldPos = new Vector3(x, y, z) + transform.position;
         Chunk   chunk    = Chunk.FindChunk(worldPos);
         if (chunk == this)
         {
             return(0);
         }
         if (chunk == null)
         {
             return(GetTheoreticalByte(worldPos));
         }
         return(chunk.GetByte(worldPos));
     }
     return(map[x, y, z]);
 }