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修改字体间距
猜你喜欢
转载自blog.csdn.net/weixin_44720673/article/details/126034799
今日推荐
周排行