In this mini-tutorial I will further expand the current implementation to allow passing your own custom tiles instead of just textures and colors.
The concept itself is relatively simple, as we are currently creating our own Custom Tile object and assigning the texture to it with its selected colors.
All we have to do is pass along our custom tile and use that instead.
This allows the creator to simply upload all his tiles into the tile palette and drag them into the configuration.
Adjusting our groundtiles and objecttiles classes.
[Serializable]
class GroundTiles
{
public GroundTileType TileType;
public Texture2D Texture;
public Color Color;
public Tile Tile; // Custom Tile
}
[Serializable]
class ObjectTiles
{
public ObjectTileType TileType;
public Texture2D Texture;
public Color Color;
public Tile Tile; // Custom Tile
}
As you can see here the highlighted lines represent our changes, we added the Unity Tile object as field to both classes. This tile we can then replace in our “InitializeTiles” method located in the TileGrid class.
Applying the custom tile to our initialization process
private Dictionary<int, Tile> InitializeTiles()
{
var dictionary = new Dictionary<int, Tile>();
foreach (var tiletype in GroundTileTypes)
{
if (tiletype.TileType == 0) continue;
// If we have a custom tile, use it otherwise create new
var tile = tiletype.Tile == null ?
CreateTile(tiletype.Color, tiletype.Texture) :
tiletype.Tile;
dictionary.Add((int)tiletype.TileType, tile);
}
foreach (var tiletype in ObjectTileTypes)
{
if (tiletype.TileType == 0) continue;
// If we have a custom tile, use it otherwise create new
var tile = tiletype.Tile == null ?
CreateTile(tiletype.Color, tiletype.Texture) :
tiletype.Tile;
dictionary.Add((int)tiletype.TileType, tile);
}
return dictionary;
}
InitializeTiles defines all the tiles in the map and caches them for further use.
Before our changes it always used to create a new tile object with our texture and color passed along.
With our change it will now use our custom tile if it is present, otherwise it will fallback to our previous flow.
So you can now easily apply your custom tiles to the tilemap configuration.

Hope this was useful to some of you, as it was requested a few times already.
Github repository commit of this tutorial can be found here:
https://github.com/Venom0us/Code2DTutorials/commit/9d4b2480431e23104afe13657b61cf6ec841cb99
Source files:
https://github.com/Venom0us/Code2DTutorials/releases/tag/v8
