示例#1
0
 public void DivedIntoChuns(int w, int h)
 {
     //根据w h 将整体的区域按照逻辑关系划分成小块
     chunkWidth      = w;
     chunkHeight     = h;
     MapChunk.Height = h;
     MapChunk.Width  = w;
     foreach (var kvp in _cells)
     {
         Vector2Int point = kvp.Key;
         MapChunk   chunk = GetMapChunk(point);
         chunk?.AddCell(point, kvp.Value);
     }
 }
示例#2
0
        MapChunk GetMapChunk(Vector2Int s)
        {
            int        x        = s.x / this.chunkWidth;
            int        y        = s.y / this.chunkHeight;
            Vector2Int chunkPos = new Vector2Int(x, y);
            MapChunk   chunk    = null;

            if (!chunkPos2chunk.ContainsKey(chunkPos))
            {
                chunk = new MapChunk(chunkPos);
                chunkPos2chunk.Add(chunkPos, chunk);
            }
            chunk = chunkPos2chunk[chunkPos];


            return(chunk);
        }