示例:
MyGeometry.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.Rendering;
public class MyGeometry : MaskableGraphic
{
// 自定义几何形状顶点
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
var color32 = color;
vh.AddVert(new Vector3(0, 0), color32, new Vector2(0, 0));
vh.AddVert(new Vector3(0, 100), color32, new Vector2(0, 1));
vh.AddVert(new Vector3(100, 100), color32, new Vector2(1, 1));
vh.AddVert(new Vector3(100, 0), color32, new Vector2(1, 0));
vh.AddVert(new Vector3(50, -50), color32, new Vector2(1, 0));
vh.AddTriangle(0, 1, 2);
vh.AddTriangle(2, 3, 0);
vh.AddTriangle(0, 3, 4);
}
}
通过调用 SetVerticesDirty() 可重新触发 OnPopulateMesh()