通过代码实现有描边有背景的雷达图
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI ;
using System.Linq;
public class LDT5 : MaskableGraphic
{
    public Texture sprite;
    public Texture backsprite;
    public Color col = Color.white;
    public float[] arr=new float[] { 1,1,2,1,1};
    Texture2D texture;
    public int num = 5;
    public override Texture mainTexture
    {
        get
        {
            if (texture == null)
            {
                if (sprite == null)
                {
                    if (material != null && material.mainTexture != null)
                    {
                        return material.mainTexture;
                    }
                }
                return sprite;
            }
            return texture;
        }
    }
    protected override void OnPopulateMesh(VertexHelper vh)
    {
        texture = new Texture2D(1024, 1024);
        Rect[] rects = texture.PackTextures(new Texture2D[] { backsprite as Texture2D, sprite as Texture2D }, 0);
        vh.Clear();
        Rect rect = rectTransform.rect;
        float r = rect.width < rect.height ? rect.width / 2 : rect.height / 2;
        float b = r / arr.Max();
        vh.AddVert(new Vector3(rect.x, rect.y, 0), col, new Vector2(rects[0].x, rects[0].y));
        vh.AddVert(new Vector3(rect.x, rect.y+rect.height, 0), col, new Vector2(rects[0].x, rects[0].y + rects[0].height));
        vh.AddVert(new Vector3(rect.x+rect.width, rect.y+rect.height, 0), col, new Vector2(rects[0].x + rects[0].width, rects[0].y + rects[0].height));
        vh.AddVert(new Vector3(rect.x+rect.width, rect.y, 0), col, new Vector2(rects[0].x + rects[0].width, rects[0].y));
        vh.AddTriangle(0, 1, 2);
        vh.AddTriangle(0, 2, 3);
        vh.AddVert(Vector3.zero, color, new Vector2(0.5f * rects[1].width + rects[1].x, 0.5f * rects[1].height + rects[1].y));
        float ang = 2 * Mathf.PI / arr.Length;
        for (int i = 0; i < arr.Length; i++)
        {
            float x = Mathf.Sin(ang * i) * arr[i] * b;
            float y = Mathf.Cos(ang * i) * arr[i] * b;
            float uvx = (r + x) / (r * 2) * rects[1].x + rects[1].width;
            float uvy = (r + y) / (r * 2) * rects[1].y + rects[1].height;
            vh.AddVert(new Vector3(x, y, 0), color, new Vector2(uvx, uvy));
            if (i == 0)
            {
                vh.AddTriangle(4, arr.Length + 4, 5);
            }
            else
            {
                vh.AddTriangle(4, i + 4, i + 5);
            }
        }
        int over = 5 + num;
        for (int i = 0; i < num; i++)
        {
            float x = Mathf.Sin(ang * i) * arr[i] * (b - 2);
            float y = Mathf.Cos(ang * i) * arr[i] * (b - 2);
            vh.AddVert(new Vector3(x, y, 0), Color.red, Vector2.zero);
            float x1 = Mathf.Sin(ang * i) * arr[i] * (b + 2);
            float y1 = Mathf.Cos(ang * i) * arr[i] * (b + 2);
            vh.AddVert(new Vector3(x1, y1, 0), Color.red, Vector2.zero);
            if (i == num - 1)
            {
                vh.AddTriangle(i * 2 + over, i * 2 + 1 + over, 1 + over);
                vh.AddTriangle(i * 2 + over, 1 + over, over);
            }
            else
            {
                vh.AddTriangle(i * 2 + over, i * 2 + 1 + over, (i + 1) * 2 + 1 + over);
                vh.AddTriangle(i * 2 + over, (i + 1) * 2 + 1 + over, (i + 1) * 2 + over);
            }
        }
    }
}

 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号