How do I use many different tile textures for one mesh? 2D Tile based game.

I am making a 2D sandbox/tile based game (like terraria/starbound), and I am restarting my tile system. I know how to create a world/chunks/tiles for the game using a single mesh per chunk. The mesh contains squares to represent each tile as you could imagine, and I map the UVs for the mesh from a single texture.

But I want to be able to make many different variations for each tile (such as dirt, stone, etc.), and these tiles would consist of fulls blocks, straight-half blocks (4 sides), and diagonal-half blocks (4 sides). And each of these 9 options would have 4+ slight variations to make the game feel more random. So that is 36 versions of a roughly 18x18pixel texture for each tile type.

The method I am using now maps the tile from a SINGLE tile sheet that is the gameobject’s material, that would contain all of the tile types, but as I added more tiles the single texture would get bigger and bigger to fit so many variations.

How can I map textures from different PNG files onto my mesh? Sorry if this is confusing, maybe there is a better method or maybe it is complicated. Any ideas would be appreciated.

Here are examples of Starbound’s and Terraria’s sprite sheet for a single tile.

99273-dirt.png

alt text

Is there a specific reason you want to use a single mesh other than reducing draw calls? Because that’s what batching is doi g for you anyway. Have SpriteRenderers with sprites from the same texture and Unity will batch draw calls for you.

I am actually creating textures in runtime its actually very fast and just one drawCall.
I was using mesh generation but the meshes have tearing so i drop the idea.

So i am just creating a chunk with a runtime texture say 64*64 tiles if i need modify i just set pixels and apply the changes.