I have a script that loops over this function, but it only draws the last quad. For example:
public class Draw_Map : Graphic
{
private static Vector2Int divisions = new Vector2Int(30, 30);
private Vector2Int[,] grid_verts = new Vector2Int[(divisions.x), (divisions.y)];
private Vector2Int[] verts = new Vector2Int[4];
private List<Vector2Int[]> quad_list = new List<Vector2Int[]>();
private bool[,] grid_sector_visited = new bool[divisions.x, divisions.y];
private int x_coord;
private int y_coord;
private UIVertex vert = UIVertex.simpleVert;
UIVertex[] vbo = new UIVertex[4];
protected UIVertex[] SetVbo(Vector2Int[] vertices)
{
for (int i = 0; i < vertices.Length; i++)
{
vert.color = color;
vert.position = new Vector2(vertices[i].x, vertices[i].y);
vbo[i] = vert;
}
return vbo;
}
protected override void OnPopulateMesh(VertexHelper vh)
{
if (Application.isPlaying && !grid_sector_visited[x_coord, y_coord])
{
grid_sector_visited[x_coord, y_coord] = true;
verts[0] = grid_verts[x_coord, y_coord];
verts[1] = grid_verts[x_coord + 1, y_coord];
verts[2] = grid_verts[x_coord + 1, y_coord + 1];
verts[3] = grid_verts[x_coord, y_coord + 1];
quad_list.Add(verts);
vh.Clear();
for (int i = 0; i < quad_list.Count; i++)
{
vh.AddUIVertexQuad(SetVbo(quad_list[i]));
}
}
}
}
where I use SetVbo() from this thread: New UI and line drawing
As I said, at the bottom, where it loops over vh.AddUIVertexQuad(), the game only displays the last quad. All previous quads in the list are not displayed. The guys in that thread I linked seem to be able to make it display all the quads in the loop, but I can’t make it work. Where is my mistake?
Also, I have another question: how do I map a texture to the quad (RectTransform)? Can I skip the material and go straight to the texture? The material doesn’t look right. Thanks