コード例 #1
0
ファイル: Tilemap.cs プロジェクト: Emolyptic/PixelGame
        /// <summary>
        /// Set a tile data in the grid position
        /// </summary>
        /// <param name="gridX"></param>
        /// <param name="gridY"></param>
        /// <param name="tileData"></param>
        public void SetTileData(int gridX, int gridY, uint tileData)
        {
            TilemapChunk chunk      = GetOrCreateTileChunk(gridX, gridY, true);
            int          chunkGridX = (gridX < 0 ? -gridX - 1 : gridX) % k_chunkSize;
            int          chunkGridY = (gridY < 0 ? -gridY - 1 : gridY) % k_chunkSize;

            if (gridX < 0)
            {
                chunkGridX = k_chunkSize - 1 - chunkGridX;
            }
            if (gridY < 0)
            {
                chunkGridY = k_chunkSize - 1 - chunkGridY;
            }
            if (m_allowPaintingOutOfBounds || (gridX >= m_minGridX && gridX <= m_maxGridX && gridY >= m_minGridY && gridY <= m_maxGridY))
            {
                chunk.SetTileData(chunkGridX, chunkGridY, tileData);
                m_markSceneDirtyOnNextUpdateMesh = true;
                // Update map bounds
                //if (tileData != Tileset.k_TileData_Empty) // commented to update the brush bounds when copying empty tiles
                {
                    m_minGridX = Mathf.Min(m_minGridX, gridX);
                    m_maxGridX = Mathf.Max(m_maxGridX, gridX);
                    m_minGridY = Mathf.Min(m_minGridY, gridY);
                    m_maxGridY = Mathf.Max(m_maxGridY, gridY);
                }
                //--
            }
        }