基于UGUI的Unity画线工具
最近项目里需要做一个画线的小游戏,LineRenderer不是很好用,自己撸了一个小工具,效果如下
下面上代码
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using FMCShape;
public class MyLineDrawer : Image
{
public List<Vector2> pointer = new List<Vector2>();
public float radio = 30;
private int headPointCount = 7;//头部顶点数量
private Vector2 offset;
protected override void Awake()
{
base.Awake();
offset = new Vector2(Screen.width * 0.5f, Screen.height * 0.5f);
}
protected override void OnPopulateMesh(VertexHelper toFill)
{
toFill.Clear();
if (pointer.Count >= 2)
{
for (int i = 1; i < pointer.Count; i++)
{
Draw(toFill, pointer[i - 1], pointer[i]);