Scriptable brushes are brushes that can draw in more ways than the default toolbarA row of buttons and basic controls at the top of the Unity Editor that allows you to interact with the Editor in various ways (e.g. scaling, translation). More info
See in Glossary, for example draw a line of tiles or random tiles. Scriptable brushes are part of the 2D Tilemap Extras package.
You can do the following:
GridBrushBase API.To use a prebuilt scriptable brush, follow these steps:
For more information about each scriptable brush, refer to Scriptable brushes in the 2D Tilemap Extras package documentation.
To create a new C# script, from the main menu select Assets > Create > MonoBehaviour script.
Open the script and replace the code with a class that inherits from UnityEngine.Tilemaps.GridBrushBase. For example:
using UnityEngine;
using UnityEngine.Tilemaps;
public class MyCustomBrush : GridBrushBase
{
}
Implement the methods of GridBrushBase to define the behavior of the brush. For example, implement the following:
Paint to add items to the grid.Erase to remove items from the grid.FloodFill to fill areas on the grid.Rotate to rotate items.Flip to flip items.ChangeZPosition and ResetZPosition to control the 3D height of items in an Isometric Z as Y tilemap.To create instances of your brush as assets in your project, add the CreateAssetMenu attribute before the class declaration.
using UnityEngine;
using UnityEngine.Tilemaps;
[CreateAssetMenu]
public class MyCustomBrush : GridBrushBase
{
// ...
}
Create an instance of the brush. For example in the previous example, from the main menu, select Assets > My Custom Brush.
The custom brush automatically appears in the Brush InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary dropdown in the Tile Palette window. For more information, refer to Tile Palette window reference.
You can also make a custom editor for a custom scriptable brush. This works the same way as custom editors for scriptable objects. The following are the main methods you would want to override when creating a custom editor:
OnPaintInspectorGUI to have an Inspector window appear on the Palette when the Brush is selected to provide additional behaviour when painting.OnPaintSceneGUI to add additional behaviours when painting on the SceneView.validTargets to have a custom list of targets which the Brush can interact with. This list of targets is shown as a dropdown list in the Palette window.CustomGridBrush attribute to your Scriptable Brush class to change its name, make it the default brush in the project, and other options.BrushTools attribute to your class with a list of compatible TilemapEditorTools types. This ensures that your Scriptable Brush only activates with these specific tools from the Tile Palette toolbar.Refer to the following for examples of a custom scriptable brush:
GridBrushBase in the API documentation for a simple example that paints GameObjectsThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info