texture tiling

Hi, i want to make a framework to texture dynamicaly creaed meshes(textures are in atlases). The point is that i dont want to use any mainTexture options etc… there are lots of examples with using mianTexture options or similar, but this is the option of material and i have full atlas on one material and i can’t set one tiling on it as long as there are very different textures. I don’t know if i describe it correctly… i know how to set an offset and i use uvs for that.

maybe ill post some of my code here:

XmlValueReader();	//give me info about texture (to public Rect AtlasUvs)
		

		//===items needed to change Tiling and Offset====
		renderer.sharedMaterial = atlasMaterial;
		
		Mesh mesh = GetComponent<MeshFilter>().mesh;
		

     	// Build the uvs 
   		Vector2[] uvs = new Vector2[mesh.vertices.Length]; 
		

		
	    uvs = mesh.uv; // Take the existing UVs 
   		for (int k = 0 ; k < uvs.Length; k++) {
			uvs[k] = new Vector2 (uvs[k].x + AtlasUvs.x/fAtlasWidth, uvs[k].y + AtlasUvs.y/fAtlasHeight); // Offset all the UV's 
		}
		
		
		mesh.uv = uvs;	// Apply the modded UV's

I need to write a similar code which makes tiling to the mesh too (not to material containing full atlas)

Any clues?

If you want to tile a subject angle of the atlas, you’ll need there to be vertices at every “tile edge” in your mesh, so you can set the appropriate UVs for each side of the tile. Just altering the UVs of the existing vertices won’t be enough.

Ok, i changed this:

for (int k = 0 ; k < uvs.Length; k++) {
			uvs[k] = new Vector2 ((AtlasUvs.width/fAtlasWidth) * uvs[k].x + AtlasUvs.x/fAtlasWidth, (AtlasUvs.height/fAtlasHeight)*uvs[k].y - (AtlasUvs.y + AtlasUvs.height)/fAtlasHeight); // Offset and tiling all the UV's 
			
			
		}

and now it works correctly. However still i’m not sure how it works… could anyone tell me why this is ok or where i have made mistake and why im lucky that it works so far? ^^