Is there anyway i can make this rule tiles to interact with another rule tiles ?
I want to make the ground have dirt and snow in order so i can’t use random and dont know how to make two rule tiles that have different sprite can interact with each other.
I don’t think you can do that. But why not incorporate both tiles in the same rue tile? The logic will be a bit complicated but you can get it right eventually.
You could make use of Custom Rule Tiles to code up a new rule for matching with Tiles of the same type but with different characteristics.
Here is an example:
using UnityEngine;
using UnityEngine.Tilemaps;
[CreateAssetMenu]
public class ExampleCustomRuleTile : RuleTile<ExampleCustomRuleTile.Neighbor>
{
public bool snow;
public class Neighbor : RuleTile.TilingRule.Neighbor
{
public const int SameTerrain = 3;
public const int DifferentTerrain = 4;
}
public override bool RuleMatch(int neighbor, TileBase tile)
{
var customRule = tile as ExampleCustomRuleTile;
switch (neighbor)
{
case Neighbor.SameTerrain:
return customRule && this.snow == customRule.snow;
case Neighbor.DifferentTerrain:
return customRule && this.snow != customRule.snow;
}
return base.RuleMatch(neighbor, tile);
}
}
You can use the new rules to match transitions between the snow and the dirt tiles?
I am trying to come up with a custom Hexagonal rule tile that can factor in various surrounding tile types and am trying to override the HexagonalRuleTile class using the above methodology, but can’t seem to bring up the regular hex fields in the inspector. I would very much like to see more documentation and examples on this subject.
The concept should be the same, except that the new class should derive from the HexagonalRuleTile instead. The Editor for this new class should also derive from the HexgonalRuleTileEditor as well.
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.Tilemaps;
[CreateAssetMenu]
public class ExampleCustomHexagonalRuleTile : HexagonalRuleTile<ExampleCustomHexagonalRuleTile.Neighbor>
{
public bool desert;
public class Neighbor : RuleTile.TilingRule.Neighbor
{
public const int SameTerrain = 3;
public const int DifferentTerrain = 4;
}
public override bool RuleMatch(int neighbor, TileBase tile)
{
var customRule = tile as ExampleCustomHexagonalRuleTile;
switch (neighbor)
{
case Neighbor.SameTerrain:
return customRule != null && this.desert == customRule.desert;
case Neighbor.DifferentTerrain:
return customRule != null && this.desert != customRule.desert;
}
return base.RuleMatch(neighbor, tile);
}
}
[CustomEditor(typeof(ExampleCustomHexagonalRuleTile))]
public class ExampleCustomHexagonalRuleTileEditor : HexagonalRuleTileEditor
{
}