示例#1
0
        private TileChunk _GetTileChunk(int tileX, int tileY, int layer)
        {
            TileChunkLayer chunkLayer = _GetTileChunkLayer(layer);

            int       rowTotalChunks = 1 + ((m_autoTileMap.MapTileWidth - 1) / k_TileChunkWidth);
            int       chunkIdx       = (tileY / k_TileChunkHeight) * rowTotalChunks + (tileX / k_TileChunkWidth);
            TileChunk tileChunk      = chunkLayer.TileChunks[chunkIdx];

            if (tileChunk == null)
            {
                int        startTileX = tileX - tileX % k_TileChunkWidth;
                int        startTileY = tileY - tileY % k_TileChunkHeight;
                GameObject chunkObj   = new GameObject();
                chunkObj.name             = "TileChunk" + startTileX + "_" + startTileY;
                chunkObj.transform.parent = chunkLayer.ObjNode.transform;
                chunkObj.hideFlags        = HideFlags.NotEditable;
                tileChunk = chunkObj.AddComponent <TileChunk>();
                chunkLayer.TileChunks[chunkIdx] = tileChunk;
                tileChunk.Configure(m_autoTileMap, layer, startTileX, startTileY, k_TileChunkWidth, k_TileChunkHeight);
            }
            return(tileChunk);
        }