Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Combine Two RuleTiles

Discussion in '2D' started by Friskeh, Feb 22, 2021.

  1. Friskeh

    Friskeh

    Joined:
    Jun 27, 2019
    Posts:
    6
    I'm trying to combine two RuleTiles in such a way that the tiles will act the exact same when touching a tile from either RuleTile. Picture of what I want it to do.

    The left is the way I want it all connected but the darker tiles connecting to the lighter tiles the same way.

    I thought an Override Rule Tile would work but it does the exact same thing.
     
    Last edited: Feb 22, 2021
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
  3. Friskeh

    Friskeh

    Joined:
    Jun 27, 2019
    Posts:
    6
    I tried implementing what you have there and it makes my RuleTile always place the default sprite almost all the time.

    Code (CSharp):
    1.     public TileBase[] friendTiles;
    2.  
    3.                 public class TileNeighbor
    4.             {
    5.                 public const int This = 1;
    6.  
    7.                 public const int ThisOrFriend = 2;
    8.  
    9.                 public const int NotThis = 3;
    10.             }
    11.  
    12.   public override bool RuleMatch(int neighbor, TileBase tile)
    13.         {
    14.             switch (neighbor)
    15.             {
    16.                 case TileNeighbor.This: return tile == this;
    17.                 case TileNeighbor.ThisOrFriend: return tile == this
    18.                          || HasFriendTile(tile);
    19.                 case TileNeighbor.NotThis: return tile != this;
    20.             }
    21.             return true;
    22.         }
    23.         bool HasFriendTile(TileBase tile)
    24.         {
    25.             if (tile == null)
    26.                 return false;
    27.             for (int i = 0; i < friendTiles.Length; i++)
    28.             {
    29.                 if (friendTiles[i] == tile)
    30.                     return true;
    31.             }
    32.             return false;
    33.         }
     
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    What does your RuleTile look like? If the Rule is set up right and the friendTiles are set up right, you might want to step through with the debugger b/c my RuleTile is very customized so there's a chance that Unity and I diverge significantly.
     
  5. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
  6. QuickiSticki

    QuickiSticki

    Joined:
    Nov 18, 2020
    Posts:
    26