当前位置:网站首页>Unity's ugui text component hard row display (improved)
Unity's ugui text component hard row display (improved)
2022-07-24 20:09:00 【The aspiration, self-improvement】
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
[ExecuteInEditMode]
[RequireComponent(typeof(Text))]
public class VirticalText : BaseMeshEffect
{
[Tooltip(" The distance between words ")]
public float spacing = 1;
private float lineSpacing = 1;
private float textSpacing = 1;
private float xOffset = 0;
private float yOffset = 0;
public override void ModifyMesh(VertexHelper helper)
{
if (!IsActive())
return;
List<UIVertex> verts = new List<UIVertex>();
helper.GetUIVertexStream(verts);
Text text = GetComponent<Text>();
TextGenerator tg = text.cachedTextGenerator;
lineSpacing = text.fontSize * text.lineSpacing;
textSpacing = text.fontSize * spacing;
xOffset = text.rectTransform.sizeDelta.x / 2 - text.fontSize / 2;
yOffset = text.rectTransform.sizeDelta.y / 2 - text.fontSize / 2;
List<UILineInfo> lines = new List<UILineInfo>();
tg.GetLines(lines);
for (int i = 0; i < lines.Count; i++)
{
UILineInfo line = lines[i];
int step = i;
if (i + 1 < lines.Count)
{
UILineInfo line2 = lines[i + 1];
int current = 0;
for (int j = line.startCharIdx; j < line2.startCharIdx - 1; j++)
{
modifyText(helper, j, current++, step, text.text.Length / 2f * text.fontSize, text.text.Length % 2 == 0 ? text.fontSize : 0, text.fontSize);
}
}
else if (i + 1 == lines.Count)
{
int current = 0;
for (int j = line.startCharIdx; j < tg.characterCountVisible; j++)
{
modifyText(helper, j, current++, step,text.text.Length/2f * text.fontSize, text.text.Length % 2==0? text.fontSize :0, text.fontSize);
}
}
}
}
void modifyText(VertexHelper helper, int i, int charYPos, int charXPos,float count,int isDouble,float fontSize)
{
UIVertex lb = new UIVertex();
helper.PopulateUIVertex(ref lb, i * 4);
UIVertex lt = new UIVertex();
helper.PopulateUIVertex(ref lt, i * 4 + 1);
UIVertex rt = new UIVertex();
helper.PopulateUIVertex(ref rt, i * 4 + 2);
UIVertex rb = new UIVertex();
helper.PopulateUIVertex(ref rb, i * 4 + 3);
Vector3 center = Vector3.Lerp(lb.position, rt.position, 0.5f);
Matrix4x4 move = Matrix4x4.TRS(-center, Quaternion.identity, Vector3.one);
float x = -charXPos * lineSpacing + xOffset;
float y = -charYPos * textSpacing + yOffset- isDouble/2;
Debug.Log(y+":."+count);
Vector3 pos = new Vector3(0, y+count-(isDouble!=0? 0 : fontSize / 2));
Matrix4x4 place = Matrix4x4.TRS(pos, Quaternion.identity, Vector3.one);
Matrix4x4 transform = place * move;
lb.position = transform.MultiplyPoint(lb.position);
lt.position = transform.MultiplyPoint(lt.position);
rt.position = transform.MultiplyPoint(rt.position);
rb.position = transform.MultiplyPoint(rb.position);
helper.SetUIVertex(lb, i * 4);
helper.SetUIVertex(lt, i * 4 + 1);
helper.SetUIVertex(rt, i * 4 + 2);
helper.SetUIVertex(rb, i * 4 + 3);
}
}
Copied the code that I don't know who improved , Now show centered alignment mode for centered
Changing the alignment mode is mainly controlled by the following code
float x = -charXPos * lineSpacing + xOffset;
float y = -charYPos * textSpacing + yOffset- isDouble/2;
Debug.Log(y+":."+count);
Vector3 pos = new Vector3(0, y+count-(isDouble!=0? 0 : fontSize / 2));
pos To control , Visual configuration improvements will be posted later
边栏推荐
- Sword finger offer 50. the first character that appears only once
- Istio二之流量劫持过程
- Implementation of OA office system based on JSP
- Use of paging assistant PageHelper
- Work notes - some problems encountered when using jest
- Working principle of envy of istio I
- 存储类别
- About the largeheap attribute
- Introduction and advanced tutorial of Albert duilib
- Introduction to WDK development 1- basic environment construction and the first driver (VS2010)
猜你喜欢

Google's display of Chrome browser icons was abandoned, and it was intended to be a small rocket

Create a life cycle aware MVP architecture

How to use the interface control telerik UI for WinForms development step progress bar?

Browser local storage webstroage

strlen函数剖析和模拟实现

C form application treeview control use

C# 窗体应用TreeView控件使用

02 | environment preparation: how to install and configure a basic PHP development environment under windows?

vlan技术

Valdo2021 - vascular space segmentation in vascular disease detection challenge (I)
随机推荐
English translation Chinese common dirty words
872. Maximum common divisor
Pure C implementation -------- Nicolas theorem
Detailed explanation of ELF format (I)
Mass modify attribute values in objects in JS
How to use the interface control telerik UI for WinForms development step progress bar?
Huawei set up login with account and password
A circle is displayed and can be moved
PD user manual
Batch download files from the server to the local
VLAN Technology
Make Huawei router into FTP server (realize upload and download function)
Leetcode 48 rotating image (horizontal + main diagonal), leetcode 221 maximum square (dynamic programming DP indicates the answer value with ij as the lower right corner), leetcode 240 searching two-d
Leetcode 560 and the subarray of K (with negative numbers, one-time traversal prefix and), leetcode 438 find all alphabetic ectopic words in the string (optimized sliding window), leetcode 141 circula
Redisgraph graphic database multi activity design scheme
strlen函数剖析和模拟实现
MySQL stored procedure
Sql164 next day retention rate of new users per day in November 2021
TCP sliding window, singleton mode (lazy and hungry) double checked locking / double checked locking (DCL)
Read the registry through the ATL library clegkey (simple and convenient)