当前位置:网站首页>Ugui force refresh of layout components
Ugui force refresh of layout components
2022-06-28 12:21:00 【Unique_ eight hundred and forty-nine million nine hundred and n】
I received a demand for planning not long ago , Make an auto fit display : Unfixed text + Unfixed button + Unfixed text , Be similar to :

For this need , The first thing that comes to mind is to add... To the parent object HorizontalLayoutGroup Components automatically manage the layout of sub objects , Add... To the sub object ContentSizeFitter The component adapts the size of the text through the content !
But the code is written , There will be overlap between the text , It is observed that as long as the parent object or one of the child objects is changed enable, The overlapping text will be displayed normally . Try to hide sub objects before loading prefabs , When the loading is completed, it will be displayed , I still have to get the desired result . Finally, I found the solution on the Internet , Use LayoutRebuilder.ForceRebuildLayoutImmediate(RT) Methods , This method is called after the loading is completed , Problem solved .
Parameters RT It's with LayoutGroup Component's RectTransform.
The following is the source code he posted :




Today, I encountered a similar problem , And sub objects will also nest content adaptive components . Empathy , Sub objects also need to have LayoutGroup Component's RectTransform Forced reconstruction .
summary :
After solving this problem , By the way LayoutRebuilder.ForceRebuildLayoutImmediate Other articles , Use ContentSizeFitter Adaptive content to set RectTransform Will take effect one frame later , If the settings don't work , You can call... At the end of the code LayoutRebuilder.ForceRebuildLayoutImmediate To redraw Layout.
Reference resources :
Husson MoMo:Unity3D Research Institute of ContentSizeFitter Synchronous immediate response callback
Tencent netizen :Unity in [VerticalLayoutGroup] And [HorizontalLayoutGroup] The dynamic refresh display is abnormal
边栏推荐
- Is there a threshold for opening futures accounts? How to open futures accounts safely on the Internet
- [C language] three sorting methods for random number files
- UGUI使用小技巧(五) Scroll Rect组件的使用
- 【编解码】从零开始写H264解码器(1) 总纲
- AcWing 609. Salary (implemented in C language)
- 女子高考落榜读专科逆袭买千万别墅,考得不好真的没关系
- Web3安全连载(3) | 深入揭秘NFT钓鱼流程及防范技巧
- Data analysis learning notes
- Chendanqi, Fang Fei, guquanquan and Li Bo won the prize, and the list of Sloan research award in 2022 was released
- 【C语言】如何很好的实现复数类型
猜你喜欢

ByteV搭建动态数字孪生网络安全平台----助力网络安全发展
![[C language] use of nested secondary pointer of structure](/img/59/8b61805431e152995c250f6dd08e29.png)
[C language] use of nested secondary pointer of structure

【北京航空航天大学】考研初试复试资料分享
![[vi/vim] basic usage and command summary](/img/bc/0be3ae3f122c3c21b480e0678095a1.png)
[vi/vim] basic usage and command summary

建立自己的网站(18)

开源项目维权成功案例: spug 开源运维平台成功维权

How to deploy the software testing environment?

【C语言】判断三角形

Convert black mask picture to color annotation file

What is the difference between internal oscillator, passive crystal oscillator and active crystal oscillator?
随机推荐
If you want to change to software testing, how can you package your resume as a test engineer with 1 year of work experience
期货开户有门槛吗,如何网上安全的开通期货账户
【Unity编辑器扩展基础】、EditorGUILayout (一)
已知两个点和中间一个比例的点,求该点坐标
[C language] use of nested secondary pointer of structure
吐血推荐17个提升开发效率的“轮子”
Bisection (integer bisection and floating point bisection)
IDEA全局搜索快捷设置
AcWing 607. Average 2 (implemented in C language)
【C语言】关于scanf()与scanf_s()的一些问题
Remoteviews layout and type restriction source code analysis
【C语言】随机数文件对其进行三种排序方法
Function and principle of remoteviews
自定义标题栏View
MapReduce项目案例1
6.A-B
Levels – 虚幻引擎场景制作「建议收藏」
【Unity编辑器扩展基础】、EditorGUILayout (三)
【经验分享】Django开发中常用到的数据库操作总结
【JS】斐波那契数列实现(递归与循环)