Files
ZHGD_Web/Assets/Script/Tool/TextTool.cs

80 lines
2.6 KiB
C#
Raw Normal View History

2025-07-13 23:16:20 +08:00
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Text))]
public class TextTool : BaseMeshEffect
{
public float xOffset;
public float yOffset;
public float xOffsetSup;
public float yOffsetSup;
public float x;
private Text text;
private string data;
private int indexStart;
private int indexEnd;
protected override void Start()
{
text = GetComponent<Text>();
}
public override void ModifyMesh(VertexHelper vh)
{
UIVertex vertex = new UIVertex();
UIVertex vertextemp1 = new UIVertex();
UIVertex vertextemp2 = new UIVertex();
UIVertex vertextemp3 = new UIVertex();
UIVertex vertextemp4 = new UIVertex();
data = Regex.Replace(text.text, @"(<color=#[0-9A-F]*>|</color>)", "");
data = Regex.Replace(data, @"(<size=\d*%>|</size>)", "");
indexStart = data.IndexOf("<sup");
indexEnd = data.IndexOf("</sup");
try
{
for (int i = 0; i < 20; i++)
{
vh.SetUIVertex(vertex, indexStart * 4 + i);
}
for (int i = 0; i < 24; i++)
{
vh.SetUIVertex(vertex, indexEnd * 4 + i);
}
for (int i = indexEnd * 4 + 24; i < vh.currentVertCount; i++)
{
vh.PopulateUIVertex(ref vertex, i);
vertex.position -= new Vector3(x,0,0);
vh.SetUIVertex(vertex, i);
}
}
catch{
}
try
{
vh.PopulateUIVertex(ref vertextemp1, indexStart * 4 + 20);
vh.PopulateUIVertex(ref vertextemp2, indexStart * 4 + 21);
vh.PopulateUIVertex(ref vertextemp3, indexStart * 4 + 22);
vh.PopulateUIVertex(ref vertextemp4, indexStart * 4 + 23);
vertextemp1.position = vertextemp1.position + new Vector3(xOffset, yOffset, 0);
vertextemp2.position = vertextemp2.position + new Vector3(xOffset + xOffsetSup, yOffset, 0);
vertextemp3.position = vertextemp3.position + new Vector3(xOffset + xOffsetSup, yOffset + yOffsetSup, 0);
vertextemp4.position = vertextemp4.position + new Vector3(xOffset, yOffset + yOffsetSup, 0);
vh.SetUIVertex(vertextemp1, indexStart * 4 + 20);
vh.SetUIVertex(vertextemp2, indexStart * 4 + 21);
vh.SetUIVertex(vertextemp3, indexStart * 4 + 22);
vh.SetUIVertex(vertextemp4, indexStart * 4 + 23);
}
catch {
}
}
}