通过顶点渲染来实现 可换行渲染
在做UI的时候有一种需求是画下划线,下面的代码是Unity2019版本下编写的“画下划线”的方法,该方法改写了大大的下划线方法(可能版本不一样,导致大佬的代码不能直接拿过来用)大佬的文字如下:
链接:一个博客里面的代码
链接:在CSDN中相同的代码
以上的内容的一样我不知道谁是原创所以都放出来了(我的代码是改写过的代码,因为我复制粘贴用不了来着)
下面的代码是我改写和完善的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using System;
public class TextUnderLine : Text
{
private float distance = 0f;
private float lineHeight = 4f;
private Color UnderLineColor;
private bool Special = false;
private List<UIVertex> m_vertexs = new List<UIVertex>();
private int m_start = 0;
private int m_end = 0;
protected override void OnPopulateMesh(VertexHelper toFill)
{
base.OnPopulateMesh(toFill); //渲染text字体的顶点
toFill.GetUIVertexStream(m_vertexs); //toFill创建vertex流
if (m_vertexs.Count <= 0) return;
SetUnderLine(toFill);
}
private void SetUnderLine(VertexHelper