当前位置:网站首页>获取Text组件内容的宽度
获取Text组件内容的宽度
2022-06-29 14:45:00 【心前阳光】
Text组件已有文字内容
//文字显示一行的需要的长度
Debug.Log(text.preferredWidth);//根据文本内容 推荐首选宽度
Text组件没有文字内容 提前获取宽度
int CalucalateTextContenWidth(Font font, string content, int fontSize, FontStyle fontStyle)
{
font.RequestCharactersInTexture(content, fontSize, fontStyle);
int width = 0;
CharacterInfo characterInfo;
//读取每个字符的信息
for (int i = 0; i < content.Length; i++)
{
font.GetCharacterInfo(content[i], out characterInfo, fontSize, fontStyle);
width += characterInfo.advance;
}
return width;
}
边栏推荐
猜你喜欢

文本预处理库spaCy的基本使用(快速入门)

Imitation headline news information DZ template discuz news information business version GBK template source code

威高血液净化冲刺香港:年营收29亿 净利降12.7%

两个字的名字如何变成有空格的3个字符的名字

How bad can a programmer be?

MySQL中100w数据表比1000w数据表查询更快吗?

EXCEL的查询功能Vlookup

Unity C# 基础复习28——带返回的委托(P449)

Redis installation in windows and Linux Environment

MySQL的json 数组操作 json_array_append、json_array_insert
随机推荐
论文学习——考虑场次降雨年际变化特征的年径流总量控制率准确核算
Uniapp problem list and experience
【Try to Hack】vulnhub DC2
I want to search the hundreds of nodes in the data warehouse. Can I check a table used in the SQL
Analysis of constant current source circuit composed of two NPN tubes
The first lesson on cloud - how easy is it to build a small broken station? The old driver of cloud computing will take you one hour to finish it
微信公众号—菜单
PostgreSQL learning (based on rookie course)
word如何自动生成目录
ROS notes (10) - Launch file startup
Draw a slash on a plane coordinate
If I am in Foshan, where can I open an account? Is it safe to open an account online?
Chapter 13 event operation of canvas
You need to know about project procurement management
MCS:离散随机变量——Binomial分布
高並發軟件(網站,服務器端接口)的評價指標
redis在window和Linux环境下的安装
Using polymorphism to realize simple calculator
第五届中国软件开源创新大赛 | openGauss赛道直播培训
知乎热议:一个程序员的水平能差到什么程度?