Class GridBrush
Default built-in brush for painting or erasing tiles and/or gameobjects on a grid.
Inherited Members
Namespace: UnityEditor .Tilemaps
Assembly: Unity.2D.Tilemap.Editor.dll
Syntax
[MovedFrom(true, "UnityEditor", "UnityEditor", null)]
public class GridBrush : GridBrushBase
Remarks
Default brush is meant for two things: Authoring GameObjects on a grid and authoring tiles on a grid. It can be used for both at the same time if necessary. Basically the default brush allows you to pick and paste tiles and GameObjects from one area to another.
Tiles in a tilemap are considered to be active for brush editing if a GameObject with Tilemap is currently selected. GameObjects are considered to be active for brush editing if their parent GameObject is currently selected.
For example: A new default brush with size of 2x3 is generated as a result of Scene view picking operation. The new instance contains six cells (GridBrush.BrushCell) and the cells are fed with tiles & GameObjects from the picking area.
Later when this brush is used in a painting operation, all the tiles and GameObjects contained in the cells are set/cloned into a new Scene position.
When creating custom brushes, it is recommended to inherit GridBrushBase by default. Inheriting GridBrush is possible when similar functionality is required, but extending it has its limits compared to base class.
It is also possible to replace the default GridBrush from the Tile Palette brush list completely by using the GridDefaultBrush attribute on one of your custom brushes and promote it to become a new default brush of the project. This is useful when higher level brush can operate as a default and protect designers from accidentally using the built-in one.
Constructors
GridBrush()
Default built-in brush for painting or erasing Tiles and/or GameObjects on a Grid.
Declaration
public GridBrush()
Properties
canChangeZPosition
Whether the brush can change Z Position
Declaration
public bool canChangeZPosition { get; set; }
Property Value
Type | Description |
---|---|
bool |
cellCount
Number of brush cells in the brush.
Declaration
public int cellCount { get; }
Property Value
Type | Description |
---|---|
int |
cells
All the brush cells the brush holds.
Declaration
public GridBrush.BrushCell[] cells { get; }
Property Value
Type | Description |
---|---|
Brush |
lastPickedCellGap
Cell Gap of the Grid which the GridBrush last picked from.
Declaration
public Vector3 lastPickedCellGap { get; }
Property Value
Type | Description |
---|---|
Vector3 |
lastPickedCellLayout
Cell Layout of the Grid which the GridBrush last picked from.
Declaration
public GridLayout.CellLayout lastPickedCellLayout { get; }
Property Value
Type | Description |
---|---|
Grid |
lastPickedCellSize
Cell Size of the Grid which the GridBrush last picked from.
Declaration
public Vector3 lastPickedCellSize { get; }
Property Value
Type | Description |
---|---|
Vector3 |
lastPickedCellSwizzle
Cell Swizzle of the Grid which the GridBrush last picked from.
Declaration
public GridLayout.CellSwizzle lastPickedCellSwizzle { get; }
Property Value
Type | Description |
---|---|
Grid |
pivot
Pivot of the brush.
Declaration
public Vector3Int pivot { get; set; }
Property Value
Type | Description |
---|---|
Vector3Int |
size
Size of the brush in cells.
Declaration
public Vector3Int size { get; set; }
Property Value
Type | Description |
---|---|
Vector3Int |
Methods
BoxErase(GridLayout, GameObject, BoundsInt)
Erases tiles and GameObjects from given bounds within the selected layers.
Declaration
public override void BoxErase(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
Parameters
Type | Name | Description |
---|---|---|
Grid |
gridLayout | Grid to erase data from. |
Game |
brushTarget | Target of the erase operation. By default the currently selected GameObject. |
Bounds |
position | The bounds to erase data from. |
Overrides
BoxFill(GridLayout, GameObject, BoundsInt)
Box fills tiles and GameObjects into given bounds within the selected layers.
Declaration
public override void BoxFill(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
Parameters
Type | Name | Description |
---|---|---|
Grid |
gridLayout | Grid to box fill data to. |
Game |
brushTarget | Target of the box fill operation. By default the currently selected GameObject. |
Bounds |
position | The bounds to box fill data into. |
Overrides
Erase(GridLayout, GameObject, Vector3Int)
Erases tiles and GameObjects in a given position within the selected layers.
Declaration
public override void Erase(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
Parameters
Type | Name | Description |
---|---|---|
Grid |
gridLayout | Grid used for layout. |
Game |
brushTarget | Target of the erase operation. By default the currently selected GameObject. |
Vector3Int | position | The coordinates of the cell to erase data from. |
Overrides
Flip(FlipAxis, CellLayout)
Flips the brush in the given axis.
Declaration
public override void Flip(GridBrushBase.FlipAxis flip, GridLayout.CellLayout layout)
Parameters
Type | Name | Description |
---|---|---|
Grid |
flip | Axis to flip by. |
Grid |
layout | Cell Layout for flipping. |
Overrides
FloodFill(GridLayout, GameObject, Vector3Int)
Flood fills tiles and GameObjects starting from a given position within the selected layers.
Declaration
public override void FloodFill(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
Parameters
Type | Name | Description |
---|---|---|
Grid |
gridLayout | Grid used for layout. |
Game |
brushTarget | Target of the flood fill operation. By default the currently selected GameObject. |
Vector3Int | position | Starting position of the flood fill. |
Overrides
GetCellIndex(int, int, int)
Gets the index to the GridBrush::ref::BrushCell based on the position of the BrushCell.
Declaration
public int GetCellIndex(int x, int y, int z)
Parameters
Type | Name | Description |
---|---|---|
int | x | X Position of the BrushCell. |
int | y | Y Position of the BrushCell. |
int | z | Z Position of the BrushCell. |
Returns
Type | Description |
---|---|
int | The index to the GridBrush::ref::BrushCell. |
GetCellIndex(int, int, int, int, int, int)
Gets the index to the GridBrush::ref::BrushCell based on the position of the BrushCell.
Declaration
public int GetCellIndex(int x, int y, int z, int sizex, int sizey, int sizez)
Parameters
Type | Name | Description |
---|---|---|
int | x | X Position of the BrushCell. |
int | y | Y Position of the BrushCell. |
int | z | Z Position of the BrushCell. |
int | sizex | X Size of Brush. |
int | sizey | Y Size of Brush. |
int | sizez | Z Size of Brush. |
Returns
Type | Description |
---|---|
int | The index to the GridBrush::ref::BrushCell. |
GetCellIndex(Vector3Int)
Gets the index to the GridBrush::ref::BrushCell based on the position of the BrushCell.
Declaration
public int GetCellIndex(Vector3Int brushPosition)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int | brushPosition | Position of the BrushCell. |
Returns
Type | Description |
---|---|
int | The index to the GridBrush::ref::BrushCell. |
GetCellIndexWrapAround(int, int, int)
Gets the index to the GridBrush::ref::BrushCell based on the position of the BrushCell. Wraps each coordinate if it is larger than the size of the GridBrush.
Declaration
public int GetCellIndexWrapAround(int x, int y, int z)
Parameters
Type | Name | Description |
---|---|---|
int | x | X Position of the BrushCell. |
int | y | Y Position of the BrushCell. |
int | z | Z Position of the BrushCell. |
Returns
Type | Description |
---|---|
int | The index to the GridBrush::ref::BrushCell. |
GetHashCode()
Returns a HashCode for the GridBrush based on its contents.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A HashCode for the GridBrush based on its contents. |
Overrides
Init(Vector3Int)
Initializes the content of the GridBrush.
Declaration
public void Init(Vector3Int newSize)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int | newSize | Size of the GridBrush. |
Init(Vector3Int, Vector3Int)
Initializes the content of the GridBrush.
Declaration
public void Init(Vector3Int newSize, Vector3Int newPivot)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int | newSize | Size of the GridBrush. |
Vector3Int | newPivot | Pivot point of the GridBrush. |
MoveEnd(GridLayout, GameObject, BoundsInt)
MoveEnd is called when user has ended the move of the area previously selected with the selection marquee.
Declaration
public override void MoveEnd(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
Parameters
Type | Name | Description |
---|---|---|
Grid |
gridLayout | Grid used for layout. |
Game |
brushTarget | Target of the move operation. By default the currently selected GameObject. |
Bounds |
position | Position where the move operation has ended. |
Overrides
MoveStart(GridLayout, GameObject, BoundsInt)
MoveStart is called when user starts moving the area previously selected with the selection marquee.
Declaration
public override void MoveStart(GridLayout gridLayout, GameObject brushTarget, BoundsInt position)
Parameters
Type | Name | Description |
---|---|---|
Grid |
gridLayout | Grid used for layout. |
Game |
brushTarget | Target of the move operation. By default the currently selected GameObject. |
Bounds |
position | Position where the move operation has started. |
Overrides
Paint(GridLayout, GameObject, Vector3Int)
Paints tiles and GameObjects into a given position within the selected layers.
Declaration
public override void Paint(GridLayout gridLayout, GameObject brushTarget, Vector3Int position)
Parameters
Type | Name | Description |
---|---|---|
Grid |
gridLayout | Grid used for layout. |
Game |
brushTarget | Target of the paint operation. By default the currently selected GameObject. |
Vector3Int | position | The coordinates of the cell to paint data to. |
Overrides
Pick(GridLayout, GameObject, BoundsInt, Vector3Int)
Picks tiles from selected Tilemaps and child GameObjects, given the coordinates of the cells.
Declaration
public override void Pick(GridLayout gridLayout, GameObject brushTarget, BoundsInt position, Vector3Int pickStart)
Parameters
Type | Name | Description |
---|---|---|
Grid |
gridLayout | Grid to pick data from. |
Game |
brushTarget | Target of the picking operation. By default the currently selected GameObject. |
Bounds |
position | The coordinates of the cells to paint data from. |
Vector3Int | pickStart | Pivot of the picking brush. |
Overrides
Reset()
Clears all data of the brush.
Declaration
public void Reset()
Rotate(RotationDirection, CellLayout)
Rotates the brush by 90 degrees in the given direction.
Declaration
public override void Rotate(GridBrushBase.RotationDirection direction, GridLayout.CellLayout layout)
Parameters
Type | Name | Description |
---|---|---|
Grid |
direction | Direction to rotate by. |
Grid |
layout | Cell Layout for rotating. |
Overrides
SetColor(Vector3Int, Color)
Sets a tint color at the position in the brush.
Declaration
public void SetColor(Vector3Int position, Color color)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int | position | Position to set the color in the brush. |
Color | color | Tint color to set in the brush. |
SetMatrix(Vector3Int, Matrix4x4)
Sets a transform matrix at the position in the brush. This matrix is used specifically for tiles on a Tilemap and not GameObjects of the brush cell.
Declaration
public void SetMatrix(Vector3Int position, Matrix4x4 matrix)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int | position | Position to set the transform matrix in the brush. |
Matrix4x4 | matrix | Transform matrix to set in the brush. |
SetTile(Vector3Int, TileBase)
Sets a Tile at the position in the brush.
Declaration
public void SetTile(Vector3Int position, TileBase tile)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int | position | Position to set the tile in the brush. |
Tile |
tile | Tile to set in the brush. |
UpdateSizeAndPivot(Vector3Int, Vector3Int)
Updates the size, pivot and the number of layers of the brush.
Declaration
public void UpdateSizeAndPivot(Vector3Int newSize, Vector3Int newPivot)
Parameters
Type | Name | Description |
---|---|---|
Vector3Int | newSize | New size of the brush. |
Vector3Int | newPivot | New pivot of the brush. |