Hi I’m trying to change the river tiles based on the neighbouring tiles.
There are 3 different types:
1 light green background
2 dark green background
3 brown background
As you can see in this pic, only the dark green background river tiles are shown and I can’t figure out why.
Here are my settings:
(3 dark green
4 brown
x light green
I’ve assigned them to the public tilebases)
And here is the script I’m using for the custom rules:
using UnityEngine;
using UnityEngine.Tilemaps;
using System.Linq;
[CreateAssetMenu(menuName = "VinTools/Custom Tiles/Advanced Rule Tile 2")]
public class CustomRuleTile_Rivers : RuleTile<CustomRuleTile_Rivers.Neighbor>
{
[Header("Advanced Tile")]
[Tooltip("If enabled, the tile will connect to these tiles too when the mode is set to \"This\"")]
public bool alwaysConnect;
[Tooltip("Tiles to connect to")]
public TileBase[] tilesToConnect3;
[Space]
[Tooltip("Tiles to connect to")]
public TileBase[] tilesToConnect4;
[Space]
[Tooltip("Tiles to connect to")]
public TileBase[] tilesToConnect5;
[Space]
[Tooltip("Check itseft when the mode is set to \"any\"")]
public bool checkSelf = false; //true;
public class Neighbor : RuleTile.TilingRule.Neighbor
{
public const int Specified3 = 3;
public const int Specified4 = 4;
public const int Specified5 = 5;
}
public override bool RuleMatch(int neighbor, TileBase tile)
{
switch (neighbor)
{
case Neighbor.This: return Check_This(tile);
case Neighbor.NotThis: return Check_NotThis(tile);
case Neighbor.Specified3: return Check_Specified3(tile);
case Neighbor.Specified4: return Check_Specified4(tile);
case Neighbor.Specified5: return Check_Specified5(tile);
}
return base.RuleMatch(neighbor, tile);
}
bool Check_This(TileBase tile)
{
if (!alwaysConnect) return tile == this;
else return tilesToConnect3.Contains(tile) || tile == this;
//.Contains requires "using System.Linq;"
}
bool Check_NotThis(TileBase tile)
{
if (!alwaysConnect) return tile != this;
else return !tilesToConnect3.Contains(tile) && tile != this;
//.Contains requires "using System.Linq;"
}
bool Check_Specified3(TileBase tile)
{
if (checkSelf) return tile != null;
else return tile != null && tile != this;
}
bool Check_Specified4(TileBase tile)
{
if (checkSelf) return tile != null;
else return tile != null && tile != this;
}
bool Check_Specified5(TileBase tile)
{
if (checkSelf) return tile != null;
else return tile != null && tile != this;
}
}
I’ve got the code from:
And changed some parts of it to fit my needs, but I don’t really understand all of it.