在UIBasicSprite中增加多边形的填充,代码如下
void PolygonFill(List<Vector3> verts, List<Vector2> uvs, List<Color> cols)
{
Vector4 u = drawingUVs;
Color c = drawingColor;
Vector2 prevX = Vector2.zero;
int vertices = mPolygonSides + 1;
float degrees = 360f / mPolygonSides;
if (mVerticesDistances.Length != vertices)
{
mVerticesDistances = new float[vertices];
for (int i = 0; i < vertices - 1; i++) mVerticesDistances[i] = 1;
}
// last vertex is also the first!
mVerticesDistances[vertices - 1] = mVerticesDistances[0];
float pointSize = localSize.x > localSize.y ? localSize.y : localSize.x;
for (int k = 0; k < vertices; k++)
{
float outer = -0.5f * pointSize * mVerticesDistances[k];
float rad = Mathf.Deg2Rad * (k * degrees + mRotation);
float radCos = Mathf.Cos(rad);
float radSin = Mathf.Sin(rad);
mTempUVs[0] = new Vector2(0, 1);
mTempUVs[1] = new Vector2(1, 1);
mTempUVs[2] = new Vector2(1, 0);
mTempUVs[3] = new Vector2(0, 0);
mTempPos[0] = prevX;
mTempPos[1] = new Vector2(outer * radCos, outer * radSin);
mTempPos[2] = Vector2.zero;
mTempPos[3] = Vector2.zero;
prevX = mTempPos[1];
for (int i = 0; i < 4; ++i)
{
verts.Add(mTempPos[i]);
uvs.Add(mTempUVs[i]);
cols.Add(c);
}
}
}
网友评论