using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using UnityEngine.Tilemaps;
|
using static UnityEngine.RuleTile.TilingRuleOutput;
|
|
[CreateAssetMenu(fileName = "CustomRuleTile", menuName = "2D/Tiles/Custom Rule Tile")]
|
public class CustomRuleTile : RuleTile<CustomRuleTile.Neighbor>
|
{
|
|
public List<TileBase> siblings = new List<TileBase>();
|
public class Neighbor : RuleTile.TilingRule.Neighbor
|
{
|
public const int Sibling = 3;
|
}
|
public override bool RuleMatch(int neighbor, TileBase tile)
|
{
|
// Handle null tiles
|
if (tile == null)
|
return neighbor == RuleTile.TilingRule.Neighbor.NotThis;
|
|
// Always allow connections to siblings or self, regardless of surrounding tiles
|
if (tile == this || siblings.Contains(tile))
|
return neighbor == RuleTile.TilingRule.Neighbor.This;
|
|
// For Sibling type explicitly
|
if (neighbor == Neighbor.Sibling)
|
return siblings.Contains(tile);
|
|
// For any other case, use base behavior
|
return base.RuleMatch(neighbor, tile);
|
}
|
}
|