实现效果
最开始是简易的雷达图的实现
```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
public class RadarMap : Graphic
{
public float[] arr;
public float r;
public override Texture mainTexture
{
get
{
if (material != null && material.mainTexture != null)
{
return material.mainTexture;
}
return s_WhiteTexture;
}
}
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
int n = arr.Length;
//最小的圆3条边
if (n>=3)
{
Rect rect = this.rectTransform.rect;
r = rect.width < rect.height ? rect.width / 2 : rect.height / 2;
float ang = 2 * Mathf.PI / n;
float p = r / arr.Max();
//圆的顶点
vh.AddVert(Vector3.zero,color,new Vector2(0.5f,0.5f));
for (int i = 0; i < n; i++)
{
float x = Mathf.Sin(i * ang) * arr[i] ;
float y = Mathf.Cos(i * ang) * arr[i] ;
float uvx = (x + r) / (2 * r);
float uvy = (y + r) / (2 * r);
vh.AddVert(new Vector3(x,y,0),color,new Vector2(uvx,uvy));
if (i == 0)
{
vh.AddTriangle(0,n,1);
}
else
{
vh.AddTriangle(0,i,i+1);
}
}
}
}
}
然后设置几个Slider 给Slider赋值脚本
```csharp
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RadarSlider : MonoBehaviour
{
public Slider[] arr;
public RadarMap map;
// Start is called before the first frame update
void Start()
{在这里插入代码片
for (int i = 0; i < arr.Length; i++)
{
arr[i].maxValue = map.r;
}
}
private void Update()
{
for (int i = 0; i < arr.Length; i++)
{
if (arr[i].value!=0)
{
map.arr[i] = arr[i].value;
map.SetAllDirty();
}
}
}
}