Scriptable tiles are tiles that dynamically change their appearance, or change the appearance of the tiles around them. Scriptable tiles are part of the 2D Tilemap Extras package.
For example, you can script tiles to change how they look based on neighboring spritesA 2D graphic objects. If you are used to working in 3D, Sprites are essentially just standard textures but there are special techniques for combining and managing sprite textures for efficiency and convenience during development. More info
See in Glossary, or play animations.
You can do either the following:
TileBase API.To create a prebuilt scriptable tile, follow these steps:
For more information, refer to Scriptable tiles in the 2D Tilemap Extras package documentation.
Follow these steps:
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.TileBase. For example:
using UnityEngine;
using UnityEngine.Tilemaps;
public class MyScriptableTile : TileBase
{
}
Implement the GetTileData method. This method determines the look of the new tile. For example:
public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
{
tileData.color = Color.white;
}
To create instances of your tile as assets in your project, add a CreateAssetMenu attribute before the class declaration.
[CreateAssetMenu]
public class MyScriptableTile : TileBase
{
...
}
Create an instance of the tile. For example in the previous example, from the main menu, select Assets > My Scriptable Tile.
Drag the tile from the Project window into a tile palette to paint with it.
Refer to the following for examples of a custom scriptable tile:
Tilemaps.TileBase.GetTileData.Tilemaps.TileBase.RefreshTile for an example of using RefreshTile to determine which other tiles run their GetTileData method when you paint the tile.