unity工具类篇 TextSpacing修改字体间距

Posted 彭老希

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity工具类篇 TextSpacing修改字体间距相关的知识,希望对你有一定的参考价值。

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

[AddComponentMenu("UI/Effects/TextSpacing")]
public class TextSpacing : BaseMeshEffect


    [SerializeField]
    public float spacing_x;
    [SerializeField]
    public float spacing_y;

    private List<UIVertex> mVertexList;

    public override void ModifyMesh(VertexHelper vh)
    
        if (spacing_x == 0 && spacing_y == 0)  return; 
        if (!IsActive())  return; 
        int count = vh.currentVertCount;
        if (count == 0)  return; 
        if (mVertexList == null)  mVertexList = new List<UIVertex>(); 
        vh.GetUIVertexStream(mVertexList);
        int row = 1;
        int column = 2;
        List<UIVertex> sub_vertexs = mVertexList.GetRange(0, 6);
        float min_row_left = sub_vertexs.Min(v => v.position.x);
        int vertex_count = mVertexList.Count;
        for (int i = 6; i < vertex_count;)
        
            if (i % 6 == 0)
            
                sub_vertexs = mVertexList.GetRange(i, 6);
                float tem_row_left = sub_vertexs.Min(v => v.position.x);
              //  Debug.LogError("min_row_left=" + min_row_left.ToString() + " tem_row_left=" + tem_row_left.ToString() + " tem_row_left <=min_row_left= " + (tem_row_left <= min_row_left).ToString());
                if (min_row_left - tem_row_left >= -10)
                
                    min_row_left = tem_row_left;
                    ++row;
                    column = 1;
                    //continue;
                
            

            for (int j = 0; j < 6; j++)
            
                UIVertex vertex = mVertexList[i];
                vertex.position += Vector3.right * (column - 1) * spacing_x;
                vertex.position += Vector3.down * (row - 1) * spacing_y;
                mVertexList[i] = vertex;
                ++i;
            
            ++column;

        
        vh.Clear();
        vh.AddUIVertexTriangleStream(mVertexList);
    

以上是关于unity工具类篇 TextSpacing修改字体间距的主要内容,如果未能解决你的问题,请参考以下文章

unity工具类篇 unity 计时器

unity工具类篇 unity 计时器

unity工具类篇 unity获取本地 / 网络时间

unity工具类篇 unity获取本地 / 网络时间

unity工具类篇 网格特效渲染适配

unity工具类篇 网格特效渲染适配