Hey,
I’m doing a 2d tile map system.
I generate a simple mesh and i’m using UV to show the terrain type (corresponding to a sprite, I mean I map the UVs to the correct part of the Texture), this way I have 1 texture, 1 material, et 1 object for the entire map.

public void UpdateUV(Vector2 t, int verticeIndex) {
this.meshData.UV [verticeIndex] = new Vector2 (
this.ux*t.x+this.px,
this.uy*t.y+this.px
);
this.meshData.UV [verticeIndex+1] = new Vector2 (
this.ux*t.x+this.px,
this.uy*t.y+(this.uy-this.py)
);
this.meshData.UV [verticeIndex+2] = new Vector2 (
this.ux*t.x+(this.ux-this.px),
this.uy*t.y+(this.uy-this.py)
);
this.meshData.UV [verticeIndex+3] = new Vector2 (
this.ux*t.x+(this.ux-this.px),
this.uy*t.y+this.py
);
}
public static Vector2 GetTextureByName(string name) {
if (name == "WaterDeep") {
return new Vector2 (2, 0);
} else if (name == "Water") {
return new Vector2 (3, 1);
} else if (name == "Sand") {
return new Vector2 (1, 1);
} else if (name == "Dirt") {
return new Vector2 (4, 0);
} else if (name == "DirtGrass") {
return new Vector2 (0, 1);
} else if (name == "DirtForest") {
return new Vector2 (3, 0);
} else if (name == "Rocks") {
return new Vector2 (5, 0);
} else if (name == "HardRocks") {
return new Vector2 (6, 0);
}
return Vector2.zero;
}
public void UpdateLayer() {
int vertexIndex = 0;
for (int x = 0; x < this.map.Width; x++) {
for (int y = 0; y < this.map.Height; y++) {
this.UpdateUV (MapPlaneController.GetTextureByName (this.map.GetTileAt (x, y).Ground.Name), verticeIndex);
vertexIndex += 4;
}
}
this.mesh.uv = this.meshData.UV;
}
I posted the code so you can see how I generate my map, it’s standard. I would like to know if there is an easy way to blend tiles textures (using a shadder?) If you need more infos don’t hestitate.
Thanks in advance for your help.
