Unity-Technologies / 2d-extras

Fun 2D Stuff that we'd like to share!
Other
1.54k stars 342 forks source link

RuleTile with sibling layer tilemaps? z-axis siblings? #374

Open 64n35h4 opened 1 year ago

64n35h4 commented 1 year ago

Hi

I'm not sure how to pharse the headline.. but I'm trying to use the module (RuleTile in specific) to create a tile for creating edge tiles (over water/lava etc..)

I got a grid with several layers I want to create 2 layers (assuming layer Ground and layer Edge) Layer Ground would be grass with patches of water (attached a picture) Layer Edge would be just the edge tiles on the border of the water patches As seen in the picture, some of the tiles work with rotation etc, because there's other this/not-this/sametype in the neightborhood (assuming they're on the same tilemap)

I was wondering how can I check for neightbors on the z-axis? tried to create a public tilemap property on the Rule and passing the relavent tilemap, but was ineffective. image image (The RED "X" are null in the Edge layer, but i'd like to "check" the type of the tile below/above/or on a layer by name?) image

Would appriciate any direction. Thank you.

ChuanXin-Unity commented 1 year ago

Hi, are the Ground and Edge layers in the same Tilemap but have different Z coordinates (eg. Edge is Z=1 and Ground is Z=0)? If you create a CustomRuleTile, you could query for Tiles in the different layers by changing the Z position.

If they are on different Tilemap GameObjects but share the same parent Grid, you could query for the different layers in GetTileData using the ITilemap to get the actual Tilemap:

public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData) { var actualTilemap = tilemap.GetComponent(); var layoutGrid = actualTilemap.layoutGrid; var tilemaps = layoutGrid.GetComponentsInChildren(); // This will get all the Tilemap layers ...

Hope this helps! Let us know if you need more information!