UGUI之修改Text字间距

来源:互联网 发布:义乌样品淘宝拍摄 编辑:程序博客网 时间:2024/05/19 08:39

我是百度搬运工
今天搬运了好多东西。。。

http://blog.csdn.net/qq_26999509/article/details/51902551

using UnityEngine;using UnityEngine.UI;using System.Collections.Generic;[AddComponentMenu("UI/Effects/TextSpacing")]//可以通过add component那个选项按钮来添加这个脚本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);            }        }    }}
0 0
原创粉丝点击