Mesh Leo雷达图!


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
public class LeoMap : MaskableGraphic
{
public float[] arr = { 1, 1, 1, 1,1 };
public Texture texture;
public override Texture mainTexture
{
get
{
if (texture == null)
{
if (material != null && material.mainTexture != null)
{
return material.mainTexture;
}
return s_WhiteTexture;
}
return texture;
}
}
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
if (arr.Length >= 3)
{
//找圆心
vh.AddVert(Vector3.zero, Color.white, new Vector2(0.5f, 0.5f));
//获取弧度
float ang = 2 * Mathf.PI / arr.Length;
//获取图片的短边
Rect rect = rectTransform.rect;
//再获取合适的半径
float r = rect.width < rect.height ? rect.width / 2 : rect.height / 2;
//比例
float p = r / arr.Max();
for (int i = 0; i < arr.Length; i++)
{
float x = Mathf.Sin(ang * i) * (arr[i] < r ? arr[i] : r) * p;
float y = Mathf.Cos(ang * i) * (arr[i] < r ? arr[i] : r) * p;
float uvx = (r + x) / (2 * r);
float uvy = (r + y) / (2 * r);
vh.AddVert(new Vector3(x, y, 0), color, new Vector2(uvx, uvy));
if (i == 0)
{
vh.AddTriangle(0, arr.Length, 1);
}
else
{
vh.AddTriangle(0, i, i + 1);
}
}
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!