Unity字体间距

直接把代码放到Text上,调整Spacing就可以了

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FontSpacing : BaseMeshEffect
{
    
    
    public float spacing = 0;
    public override void ModifyMesh(VertexHelper vh)
    {
    
    
        List<UIVertex> vertexs = new List<UIVertex>();
        vh.GetUIVertexStream(vertexs);
        int vertexIndexCount = vertexs.Count;
        for (int i = 6; i < vertexIndexCount; i++)
        {
    
    
            UIVertex v = vertexs[i];
            v.position += new Vector3(spacing * (i / 6), 0, 0);
            vertexs[i] = v;
            if (i % 6 <= 2)
            {
    
    
                vh.SetUIVertex(v, (i / 6) * 4 + i % 6);
            }
            if (i % 6 == 4)
            {
    
    
                vh.SetUIVertex(v, (i / 6) * 4 + i % 6 - 1);
            }
        }
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FontSpacing : BaseMeshEffect
{
public float spacing = 0;
public override void ModifyMesh(VertexHelper vh)
{
List vertexs = new List();
vh.GetUIVertexStream(vertexs);
int vertexIndexCount = vertexs.Count;
for (int i = 6; i < vertexIndexCount; i++)
{
UIVertex v = vertexs[i];
v.position += new Vector3(spacing * (i / 6), 0, 0);
vertexs[i] = v;
if (i % 6 <= 2)
{
vh.SetUIVertex(v, (i / 6) * 4 + i % 6);
}
if (i % 6 == 4)
{
vh.SetUIVertex(v, (i / 6) * 4 + i % 6 - 1);
}
}
}
}

猜你喜欢

转载自blog.csdn.net/qiao2037641855/article/details/125216282