/// <summary>
/// 雷达图
/// </summary>
public class ldt : MaskableGraphic
{
//将代码放在Image图片上
public float[] arr;
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
int n = arr.Length;
if(n>=3)
{
Rect rect = this.rectTransform.rect;
float r = rect.width < rect.height ? rect.width / 2 : rect.height / 2;
float p = r / arr.Max();
float ang = 2 * Mathf.PI / n;
vh.AddVert(Vector3.zero, Color.white, new Vector2(0.5f, 0.5f));
for (int i = 0; i < n; i++)
{
float x = Mathf.Sin(i * ang) * arr[i] * p;
float y = Mathf.Cos(i * ang) * arr[i] * p;
float ux = (x + r) / (r * 2);
float uy = (y + r) / (r * 2);
vh.AddVert(new Vector3(x,y,0), Color.white, new Vector2(ux,uy));
if(i==0)
{
vh.AddTriangle(0, n, 1);
}
else
{
vh.AddTriangle(0, i, i + 1);
}
}
}
}
public void Btn()
{
SetAllDirty();
}
// Update is called once per frame
void Update()
{
}
}
标签:arr,ang,vh,float,Mathf,雷达,rect From: https://www.cnblogs.com/cxh123/p/17305932.html