public void SetOneQuadMesh(Rect drawRect, Rect uvRect, Color color, Color[] allColors = null)
{
//当四边形发生形变时,只用两个三角面表达会造成图形的变形较严重,这里做一个优化,自动增加更多的面
if (vertexMatrix != null)
{
Alloc(9);
FillVerts(0, drawRect);
FillUV(0, uvRect);
Vector2 camPos = cameraPosition != null ? (Vector2)cameraPosition : Vector2.zero;
if (camPos.x == 0)
camPos.x = drawRect.x + drawRect.width / 2;
if (camPos.y == 0)
camPos.y = -(drawRect.y + drawRect.height / 2);
float cx = uvRect.x + (camPos.x - drawRect.x) / drawRect.width * uvRect.width;
float cy = uvRect.y - (camPos.y - drawRect.y) / drawRect.height * uvRect.height;
vertices[4] = new Vector3(camPos.x, camPos.y, 0);
vertices[5] = new Vector3(drawRect.xMin, camPos.y, 0);
vertices[6] = new Vector3(camPos.x, -drawRect.yMin, 0);
vertices[7] = new Vector3(drawRect.xMax, camPos.y, 0);
vertices[8] = new Vector3(camPos.x, -drawRect.yMax, 0);
uv[4] = new Vector2(cx, cy);
uv[5] = new Vector2(uvRect.xMin, cy);
uv[6] = new Vector2(cx, uvRect.yMax);
uv[7] = new Vector2(uvRect.xMax, cy);
uv[8] = new Vector2(cx, uvRect.yMin);
this.triangles = TRIANGLES_4_GRID;
}
else
{
Alloc(4);
FillVerts(0, drawRect);
FillUV(0, uvRect);
this.triangles = TRIANGLES;
}
if (allColors != null)
{
Color32[] arr = this.colors;
int count = arr.Length;
for (int i = 0; i < count; i++)
arr[i] = allColors[i % allColors.Length];
}
else
FillColors(color);
UpdateMesh();
}