using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[AddComponentMenu("UI/Effects/FontBeatOne")]
public class FontBeatOne : BaseMeshEffect
{
const int count = 6;
[SerializeField]
public float StartIndex;
[SerializeField]
public float EndIndex;
[Tooltip("速度")]
[SerializeField]
public float Speed;
protected Text m_text;
protected List<UIVertex> vertices = new List<UIVertex>();
protected List<UIVertex> newVerts = new List<UIVertex>();
protected override void Start()
{
m_text = GetComponent<Text>();
base.Start();
}
public override void ModifyMesh(VertexHelper vh)
{
vertices.Clear();
newVerts.Clear();
vh.GetUIVertexStream(vertices);
for (int i = 0; i < (vertices.Count / count); i++)
{
if (i >= StartIndex && i < EndIndex)
{
newVerts.AddRange(Characters(vertices.GetRange(i * count, count), i));
}
else
{
newVerts.AddRange(vertices.GetRange(i * count, count));
}
}
StartIndex += (Speed / 10);
vh.Clear();
vh.AddUIVertexTriangleStream(newVerts);
}
protected List<UIVertex> Characters(List<UIVertex> verts, int characterindex)
{
for (int i = 0; i < verts.Count; i++)
{
UIVertex c = verts[i];
c.color.a = Byte.MinValue;
verts[i] = c;
}
return verts;
}
void Update()
{
UpdateBeat();
}
public void UpdateBeat()
{
m_text.SetVerticesDirty();
}
}
Unity Text文字出现效果
于 2022-06-29 10:40:53 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)