字体间距

2017-08-03  本文已影响0人  归隐3中
image.png

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.Collections.Generic;

[AddComponentMenu("UI/Effects/TextSpacing")]
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++)
    {
        //第一个字不用改变位置
        vt = vertexs[i];
        vt.position += new Vector3(_textSpacing * (i / 6), 0, 0);
        vertexs[i] = vt;
        //以下注意点与索引的对应关系
        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);
        }
    }
}

}

上一篇 下一篇

猜你喜欢

热点阅读