Dynamic tile seams (joins)

Registered: 2016-08-10
Posts: 12



Is it possible for a brush to "autodetect" what brushes are painted next to it and, based on that, decide which seam/join to use?

For example, if I draw dirt next to water, draw a coast tile sprite (dirt-water join). But if draw using the same dirt brush next to grass, draw a dirt-to-grass transition sprite instead.

Lea Hayes
Rotorz Limited
From: United Kingdom
Registered: 2014-03-04
Posts: 638

Response 1


Sorry for the late response.

You could create a custom editor script that hooks into the PaintingUtility.TilePainted event. This happens after the first tile is painted, but, you could probably use this to switch to the desired brush and then re-paint that tile using the newly selected brush.

The currently selected brush can be changed by setting the ToolUtility.SelectedBrush property.

You can use the Unity attribute InitializeOnLoad to have your editor script register itself.

For example:

using UnityEditor;
using UnityEngine;
using Rotorz.Tile;
using Rotorz.Tile.Editor;

public static class CustomTilePaintingExtension
    static CustomTilePaintingExtension()
        PaintingUtility.TilePainted += PaintingUtility_TilePainted;

    private static void PaintingUtility_TilePainted(TilePaintedEventArgs args)
        // Get tile to left or right of the painted tile.
        var adjacentTile = args.TileSystem.GetTileOrNull(
            args.TileIndex.column > 0
                ? args.TileIndex.column - 1
                : args.TileIndex.column + 1

        if (adjacentTile != null && adjacentTile.brush != null) {
            // TODO: Lookup the brush that you want to use...
            Brush desiredBrush = ...;
            // Select the desired brush.
            ToolUtility.SelectedBrush = desiredBrush;
            // Re-paint the tile using the desired brush.
            desiredBrush.PaintWithSimpleRotation(args.TileSystem, args.TileIndex, args.TileData.PaintedRotation, args.TileData.variationIndex);

Obviously depending upon which tiles have already been painted you may have an ambiguous situation where the tile on the left says that you need a sandy transition whilst the tile on the right says you need a grassy transition. So you would need to just go with one of them I guess.

Disclaimer: the above code has not been tested.

I hope that this helps with your project!

Many thanks