I’ve been working on my own version of a terrain tile that uses unique images for every tile direction instead of rotating them like the one in 2D extras does. (It’s for a platformer, so I want visual variety in the sides/top/bottom)
Rather than make every possible combination of tiles with an indented corner, I want to add the corner details as overlays when they’re necessary.
Unfortunately, I haven’t yet found a way to do this due to weirdness in the Tilemap API.
I ruled out the option of instantiating a game object for every tile that needed corner details and then stacking sprite renderers based on how many corners the tile had - I assume adding additional hundreds/thousands of GO’s is a bad idea, though I could be wrong.
This is where the API design gets confusing. In order to manipulate tile data, I need an instance of ITilemap. But… ITilemap is not an interface, it’s a class. And Tilemap is not a subclass of ITilemap. No, ITilemap is a completely separate class that only seems to exist/be accessible when passed by the editor itself to GetTileData while painting tiles. And it’s not even ITilemap - it’s UnityEditor.EditorPreviewTilemap, which is not documented anywhere. Furthermore, Tilemap’s API contains everything that ITilemap has, which makes the inclusion of ITilemap even more confusing. It also has a GetEditorPreviewTile() method, which seems to obviate the need for ITilemap.
I tried to manipulate the contents of my corner overlay layers while creating the terrain tiles, but since I only have access to the ITilemap instance currently being used for the current tilemap, I seem to be able to set all the tilemap data I need to correctly while simultaneously completely screwing up the editor preview for the current tilemap layer.
So my next idea was to handle all of this via menu item and see if I could get the correct tile info from outside the tile base API. Turns out, that’s not really possible.
Why? TileBase has no accessor to location on its own, so if I want to iterate through all tiles and then make changes based on what I find, I cannot simply call tilemap.GetTilesBlock (tilemap.cellBounds); and then iterate through the results - I have no access to the positions of those tiles AND I don’t have access to an instance of ITilemap, so I can’t call tile.GetTileData().
Am I just not expected to ever make modifications to Tilemaps outside of the tilemap tools? Or is there some fundamental piece of information about the tilemap API that I missed?
Thanks!