miepzerino
2025-04-01 ff3f9c75fccb3fbb7b882ec29e754e6135b53e60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
    }
}