欢迎来到我的博客!

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);
}

}
}
}
}

 

posted @   梦凡尘_mzz  阅读(32)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示