示例#1
0
        public void CutRect(TileMap tilemap, int startGridX, int startGridY, int endGridX, int endGridY)
        {
            if (is_undo_enabled)
            {
#if UNITY_EDITOR
                Undo.RecordObject(tilemap, TileMapConst.Undo_Operation_Name + tilemap.name);
                Undo.RecordObjects(tilemap.GetComponentsInChildren <TileMapChunk>(),
                                   TileMapConst.Undo_Operation_Name + tilemap.name);
#endif
            }

            tilemap.is_undo_enabled = is_undo_enabled;

            for (int gridY = startGridY; gridY <= endGridY; ++gridY)
            {
                for (int gridX = startGridX; gridX <= endGridX; ++gridX)
                {
                    tileMap.SetTileData(gridX - startGridX, gridY - startGridY, tilemap.GetTileData(gridX, gridY));
                    tilemap.SetTileData(gridX, gridY, TileSetConst.TileData_Empty);
                }
            }

            tileMap.UpdateMeshImmediate();
            tilemap.UpdateMeshImmediate();

            tilemap.is_undo_enabled = false;
        }
示例#2
0
        public void Erase(TileMap tileMap, Vector2 local_pos)
        {
            int minGridX = this.tileMap.min_grid_x;
            int minGridY = this.tileMap.min_grid_y;
            int maxGridX = this.tileMap.max_grid_x;
            int maxGridY = this.tileMap.max_grid_y;

            if (is_undo_enabled)
            {
#if UNITY_EDITOR
                Undo.RecordObject(tileMap, TileMapConst.Undo_Operation_Name + tileMap.name);
                Undo.RecordObjects(tileMap.GetComponentsInChildren <TileMapChunk>(),
                                   TileMapConst.Undo_Operation_Name + tileMap.name);
#endif
            }

            tileMap.is_undo_enabled = is_undo_enabled;
            int dstGy = TileSetBrushUtil.GetGridY(local_pos, tileMap.cell_size);
            for (int gridY = minGridY; gridY <= maxGridY; ++gridY, ++dstGy)
            {
                int dstGx = TileSetBrushUtil.GetGridY(local_pos, tileMap.cell_size);
                for (int gridX = minGridX; gridX <= maxGridX; ++gridX, ++dstGx)
                {
                    tileMap.SetTileData(dstGx, dstGy, TileSetConst.TileData_Empty);
                }
            }

            tileMap.UpdateMeshImmediate();
            tileMap.is_undo_enabled = false;
        }
示例#3
0
        public void Paint(TileMap tileMap, Vector2 local_pos, bool skipEmptyTiles = false)
        {
            int min_grid_x = this.tileMap.min_grid_x;
            int min_grid_y = this.tileMap.min_grid_y;
            int max_grid_x = this.tileMap.max_grid_x;
            int max_grid_y = this.tileMap.max_grid_y;

            if (is_undo_enabled)
            {
#if UNITY_EDITOR
                Undo.RecordObject(tileMap, TileMapConst.Undo_Operation_Name + tileMap.name);
                Undo.RecordObjects(tileMap.GetComponentsInChildren <TileMapChunk>(),
                                   TileMapConst.Undo_Operation_Name + tileMap.name);
#endif
            }

            tileMap.is_undo_enabled = is_undo_enabled;
            int  target_grid_y     = TileSetBrushUtil.GetGridY(local_pos, tileMap.cell_size);
            bool is_do_paint_empty =
                this.tileMap.GridWidth == 1 && this.tileMap.GridHeight == 1 || // don't copy empty tiles
                brushPattern != null && brushPattern.GetLength(0) == 1 &&
                brushPattern.GetLength(1) == 1; // unless the brush size is one
            is_do_paint_empty &= !skipEmptyTiles;



            for (int grid_y = min_grid_y; grid_y <= max_grid_y; ++grid_y, ++target_grid_y)
            {
                int target_grid_x = TileSetBrushUtil.GetGridX(local_pos, tileMap.cell_size);
                for (int grid_x = min_grid_x; grid_x <= max_grid_x; ++grid_x, ++target_grid_x)
                {
                    uint tileData = this.tileMap.GetTileData(grid_x, grid_y);
                    if (
                        is_do_paint_empty ||
                        tileData != TileSetConst.TileData_Empty
                        )
                    {
                        tileMap.SetTileData(target_grid_x, target_grid_y, tileData);
                    }
                }
            }

            tileMap.UpdateMeshImmediate();
            tileMap.is_undo_enabled = false;
        }
示例#4
0
        public void FloodFill(TileMap tileMap, Vector2 local_pos)
        {
            if (is_undo_enabled)
            {
#if UNITY_EDITOR
                Undo.RecordObject(tileMap, TileMapConst.Undo_Operation_Name + tileMap.name);
                Undo.RecordObjects(tileMap.GetComponentsInChildren <TileMapChunk>(),
                                   TileMapConst.Undo_Operation_Name + tileMap.name);
#endif
            }

            tileMap.is_undo_enabled = is_undo_enabled;

            TileMapDrawingUtil.FloodFill(tileMap, local_pos, GetBrushPattern());
            tileMap.UpdateMeshImmediate();

            tileMap.is_undo_enabled = false;
        }
示例#5
0
 public void FlipV(bool changeFlags = true)
 {
     tileMap.FlipV(changeFlags);
     tileMap.UpdateMeshImmediate();
 }