I am trying to create a custom Rule tile in unity.
TLDR: I am seeking to make a rule in my ruletile that allows for parts of a tile that "sticks out" of the tiles at the top, to have higher priority than the tiles you place on the tile fields on top of it.
The thing is, my tileset has tiles that "bleed in" to the two tiles on top of it. But when I draw with the rule tile, the "overflow" is shown under the tiles above it, making the borders clip, with no overflow.
To better explain the actual visual - for example - a forest tile when placed alone has trees that slightly go over the top of the hexagon. Placing tiles on top of that, these trees should be - in the rule tile, visible over the tiles on top of it, so they blend. Instead, the trees that go over the actual tile are cut by the top tiles.
I have tried making a custom hexagonal rule tile script, but it is not working.
using UnityEngine;
using UnityEngine.Tilemaps;
using System.Collections.Generic;
[CreateAssetMenu(fileName = "New Custom Hexagonal Rule Tile", menuName = "Tiles/Custom Hexagonal Rule Tile")]
public class CustomHexagonalRuleTile : HexagonalRuleTile
{
public List<TileBase> possibleTiles; // List of possible tiles that share the same directional rules
// Define the positions of the neighbors in a pointy top hexagonal grid
private static readonly Vector3Int[] HexagonalNeighbors = new Vector3Int[]
{
new Vector3Int(1, 0, 0), // Right
new Vector3Int(1, -1, 0), // Bottom Right
new Vector3Int(0, -1, 0), // Bottom Left
new Vector3Int(-1, 0, 0), // Left
new Vector3Int(-1, 1, 0), // Top Left
new Vector3Int(0, 1, 0) // Top Right
};
public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
{
base.GetTileData(position, tilemap, ref tileData);
// Check for overflow from the Top Right
Vector3Int topRight = position + HexagonalNeighbors[5];
if (tilemap.GetTile(topRight) == this)
{
// Handle overflow from the Top Right
// Randomly select a tile from the list of possible tiles
if (possibleTiles != null && possibleTiles.Count > 0)
{
TileBase selectedTile = possibleTiles[Random.Range(0, possibleTiles.Count)];
tileData.sprite = ((Tile)selectedTile).sprite; // Set the sprite of the selected tile
tileData.transform = Matrix4x4.Translate(new Vector3(0, 0.5f, 0)); // Adjust the position to show overflow
}
}
// Check for overflow from the Top Left
Vector3Int topLeft = position + HexagonalNeighbors[4];
if (tilemap.GetTile(topLeft) == this)
{
// Handle overflow from the Top Left
// Randomly select a tile from the list of possible tiles
if (possibleTiles != null && possibleTiles.Count > 0)
{
TileBase selectedTile = possibleTiles[Random.Range(0, possibleTiles.Count)];
tileData.sprite = ((Tile)selectedTile).sprite; // Set the sprite of the selected tile
tileData.transform = Matrix4x4.Translate(new Vector3(0, 0.5f, 0)); // Adjust the position to show overflow
}
}
}
}
I think maybe the issue is I am not correctly able to specify programmatically what the "overflow" is. Has anyone ever had any experience with this?
Edit: Here is a link to an image where I try to outline it:
As you can see, there is an overflow into the empty tiles on top of it, but, when I place a tile, the "overflow" disappears, making them fit less snugly together. I apologize for not adding this in the beginning :)