当前位置:网站首页>UGUI使用小技巧(六)Unity实现字符串竖行显示
UGUI使用小技巧(六)Unity实现字符串竖行显示
2022-06-28 12:00:00 【Unique_849997563】
最近遇到一个问题,策划需求,文字像古书那样,从右到左,竖行显示。
以前一直以为UGUI的Text可以满足这个需求,我以为可以设置某个属性,就将现在横排显示的文本变成竖行,做个东西的时候没有找到原生的解决方案,然后在网上简单的扒了一圈,发现有两种解决方法。
第一种是,将设置到Text组件的文本行转列其余的用空格显示。
第二种是重写Text组将的一些函数,具体怎么弄的没看明白。
然后这两种方法我都试了一下,都有Bug,然后我就用一种简单的方法替代了,能解决当前问题。
我是用GridLayoutGroup组件实现这个功能的:
1、在GameObject上添加Text组件做成一个预制Item;
2、将需要竖行显示的文本字符串装换成Char数组;
3、循环数组,实例化Item,将Char数组里面的值设置到Item的Text组件里面, 一个Item设置一个值;(如果你文本里面有换行,你需要计算空格添加到Array或List里面)
4、设置GridLayoutGroup属性,利用GridLayoutGroup实现竖行显示文本的功能。

这里是我GridLayoutGroup设置的属性。效果图如下:

以上就是我通过GridLayoutGroup组件实现字符串竖行显示的方法,如果你文本不多、固定不变的,可以使用这种方法,如果你文本比较多,转出来的字符数组比较大,不建议这样使用。最好的办法应该还是重写Text吧,但是我看了Text源码,不知道从哪里着手。
如果你有更好的方法,期待你的分享!
边栏推荐
- 6.A-B
- Chendanqi, Fang Fei, guquanquan and Li Bo won the prize, and the list of Sloan research award in 2022 was released
- Self use demo of basic component integration of fluent
- Join hands with cigent: group alliance introduces advanced network security protection features for SSD master firmware
- NFT card chain game system development DAPP construction technical details
- Contract quantitative trading system development | contract quantitative app development (ready-made cases)
- Chapter 2 do you remember the point, line and surface (2)
- AcWing 605. Simple product (implemented in C language)
- cdc同步 如果数据库表的主键发生了变化,会同步成两个数据 还是会同步更新主键呢?
- . Net hybrid development solution 24 webview2's superior advantages over cefsharp
猜你喜欢

ByteV搭建动态数字孪生网络安全平台----助力网络安全发展

How to deploy the software testing environment?

Leetcode 705. 设计哈希集合

Convert black mask picture to color annotation file

【C语言】如何产生正态分布或高斯分布随机数

Array method in JS 2021.09.18

Day29 JS notes 2021.09.23

Redis 原理 - List

Graphics view framework for QT learning (to realize startup animation)

Day31 JS notes DOM 2021.09.26
随机推荐
6.A-B
深度学习又有新坑了!悉尼大学提出全新跨模态任务,用文本指导图像进行抠图...
MapReduce项目案例3——温度统计
Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
SoapUI rookie tutorial
Graphics view framework for QT learning (to realize startup animation)
IO stream of file and Base64
【C语言】判断三角形
Leetcode 48. 旋转图像(可以,已解决)
水果FL Studio/Cubase/Studio one音乐宿主软件对比
【C语言】关于scanf()与scanf_s()的一些问题
Fruit FL studio/cubase/studio one music host software comparison
Necessary for beginners PR 2021 quick start tutorial, PR green screen matting operation method
Difference (one dimension)
【C语言】如何产生正态分布或高斯分布随机数
Multi dimensional monitoring: the data base of intelligent monitoring
Android应用安全之JNI混淆
Convert black mask picture to color annotation file
How to deploy the software testing environment?
Web3 security serials (3) | in depth disclosure of NFT fishing process and prevention techniques