public static void SetUV(MaterialData mat, Mesh mesh, UVMapFn mapFn) { List <Vector2> uvs = new List <Vector2>(); for (int i = 0; i < mesh.vertices.Length; ++i) { uvs.Add(Vector2.zero); } for (int i = 0; i < mesh.triangles.Length; i += 3) { int t1 = mesh.triangles[i]; int t2 = mesh.triangles[i + 1]; int t3 = mesh.triangles[i + 2]; TriangleData td = new TriangleData(t1, t2, t3); Vector3 va = mesh.vertices[t1]; Vector3 vb = mesh.vertices[t2]; Vector3 vc = mesh.vertices[t3]; TriangleData.SetX(td, va.x, vb.x, vc.x); TriangleData.SetY(td, va.y, vb.y, vc.y); TriangleData.SetZ(td, va.z, vb.z, vc.z); mapFn(mat, td, uvs); } mesh.SetUVs(0, uvs); }