Unity的UGUI中能够显示出来的内容基本都继承于Graphic类,该类中有一个虚函数OnPopulateMesh。该函数用于构建显示所需的网格数据。因此,可以通过重写该方法,定义线条的网格,由此在Canvas上绘制线段。
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UILine : Graphic
{
public float size = 5;
public List<Vector2> points;
protected override void OnPopul