2d-extras icon indicating copy to clipboard operation
2d-extras copied to clipboard

Can't get the custom sibling rule to work with package

Open LtGab opened this issue 4 years ago • 2 comments

Hello,

I'm trying to add the sibling custom rule tile but I get this error :

image

Here's the code I use for the sibling :

`public` class SiblingRuleTile : RuleTile<SiblingRuleTile.Neighbor>
{
    public int siblingGroup;
    public class Neighbor : RuleTile.TilingRule.Neighbor
    {
        public const int Sibing = 3;
    }
    public override bool RuleMatch(int neighbor, TileBase tile)
    {
        SiblingRuleTile myTile = tile as SiblingRuleTile;
        switch (neighbor)
        {
            case Neighbor.Sibing: return myTile && myTile.siblingGroup == siblingGroup;
        }
        return base.RuleMatch(neighbor, tile);
    }
}

Is there a solution to this ?

Also, my RuleTile.cs function is named RuleMatches and not RuleMatch, so I guess it shouldn't even work ?

public bool RuleMatches(TilingRule rule, Vector3Int position, ITilemap tilemap, int angle)
		{
			for (int y = -1; y <= 1; y++)
			{
				for (int x = -1; x <= 1; x++)
				{
					if (x != 0 || y != 0)
					{
						Vector3Int offset = new Vector3Int(x, y, 0);
						Vector3Int rotated = GetRotatedPos(offset, angle);
						int index = GetIndexOfOffset(rotated);
						TileBase tile = tilemap.GetTile(position + offset);
						if (rule.m_Neighbors[index] == TilingRule.Neighbor.This && tile != this || rule.m_Neighbors[index] == TilingRule.Neighbor.NotThis && tile == this)
						{
							return false;
						}	
					}
				}
				
			}
			return true;
		}

LtGab avatar Feb 04 '21 14:02 LtGab

Hi, would it be possible to share the version of the 2D Extras you are using and how you have added it to your project?

It seems like you are using an older version of the RuleTile code which does not allow to access RuleTile.TilingRule.Neighbor and RuleTile.RuleMatch. Updating the 2D Extras package to the current versions should help with this. You can access the package through the Unity Package Manager with Unity 20.1 and above, or retry the instructions from the README in this repository (You may need to remove the Packages/package-lock.json file from your project!).

Let us know if this works out for you!

ChuanXin-Unity avatar Feb 05 '21 02:02 ChuanXin-Unity

Yeah, you're right. I had a couple of errors with the packages. Everything works fine now.

Thanks !

LtGab avatar Feb 05 '21 14:02 LtGab