最近要做一个demo,要求就是快,其中有一个需求就是要做一个直角三角形图片。我发现就算三角形的各个顶点位置比较难,发现一哥们写了个手动控制图片的形状,本来是用在雷达图上的,我发现我可以直接拿来摆一个三角形。现在分享给大家。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Area : Graphic {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update()
{
SetAllDirty ();
}
protected override void OnPopulateMesh(VertexHelper vh)
{
if (transform.childCount == 0) {
return;
}
Color32 color32 = color;
vh.Clear();
// 几何图形的顶点,本例中根据子节点坐标确定顶点
foreach (Transform child in transform) {
vh.AddVert(child.localPosition, color32, new Vector2(0f, 0f));
}
// 几何图形中的三角形
vh.AddTriangle(0, 1, 2);
vh.AddTriangle(2, 3, 0);
}
}