miduo_client/Assets/LuaFramework/Scripts/Common/TextSpacing.cs

43 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
[AddComponentMenu("UI/Effects/TextSpacing")]
[ExecuteInEditMode]
public class TextSpacing : BaseMeshEffect
{
public float _textSpacing = 1f;
public override void ModifyMesh(VertexHelper vh)
{
if (!IsActive() || vh.currentVertCount == 0)
{
return;
}
List<UIVertex> vertexs = new List<UIVertex>();
vh.GetUIVertexStream(vertexs);
int indexCount = vh.currentIndexCount;
UIVertex vt;
for (int i = 6; i < indexCount; i++)
{
//第一个字不用改变位置,且一个字在 List<UIVertex>中占6个位置第一个字既0-5
vt = vertexs[i];
vt.position += new Vector3(_textSpacing * (i / 6), 0, 0);
vertexs[i] = vt;
//以下注意点与索引的对应关系,
//注:经测试,一个字符的三角面的顶点记录顺序为顺时针从左上角的点开始计数 0 1 2 3 4 5
//而第3个顶点和第2个顶点重合第5个顶点和第0个顶点重合所以只需要修改4个顶点就能修改该字符的偏移
if (i % 6 <= 2)
{
vh.SetUIVertex(vt, (i / 6) * 4 + i % 6);
}
if (i % 6 == 4)
{
vh.SetUIVertex(vt, (i / 6) * 4 + i % 6 - 1);
}
}
}
}