using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Rectangular : Graphic//这个类加上后自动添加渲染和网格组件
{
protected override void OnPopulateMesh(VertexHelper vh)//开始填充网格
{
vh.Clear();//清空顶点坐标
Rect rect = this.rectTransform.rect;//获取当前载体位置
//添加顶点
vh.AddVert(new Vector3(rect.x, rect.y, 0), color, Vector2.zero);//0,0 原点
vh.AddVert(new Vector3(rect.x, rect.y + rect.height, 0), color, Vector2.up);//0,1 Y
vh.AddVert(new Vector3(rect.x + rect.width, rect.y, 0), color, Vector2.right); //1,0 X
vh.AddVert(new Vector3(rect.x + rect.width, rect.y + rect.height, 0), color, Vector2.one);//1,1
//绘制
vh.AddTriangle(0,1,2);
vh.AddTriangle(1,3,2);
}
// Update is called once per frame
void Update()
{
}
}
标签:Vector3,vh,Vector2,方形,网格,color,new,制作,rect From: https://www.cnblogs.com/qinhuanghan5/p/17029754.html