当前位置:网站首页>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
边栏推荐
- SHA256加密工具类
- [C language] use of file read / write function
- Connectionreseterror: [winerror 10054] the remote host forced an existing connection to be closed
- Daily practice of C language - day 3: calculate the number of occurrences of sub strings of strings
- 杰理之wif 干扰蓝牙【篇】
- PrecomputedTextCompat用法及原理
- 开源项目维权成功案例: spug 开源运维平台成功维权
- Prepare for Jin San Yin Si I. testers without experience in automated testing projects should look at it quickly
- Levels – 虚幻引擎场景制作「建议收藏」
- AcWing 610. Salary and bonus (implemented in C language)
猜你喜欢
![[vi/vim] basic usage and command summary](/img/bc/0be3ae3f122c3c21b480e0678095a1.png)
[vi/vim] basic usage and command summary

In less than an hour, apple destroyed 15 startups

Remoteviews layout and type restriction source code analysis

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

Many benefits of SEO optimization are directly related to traffic

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

【Unity编辑器扩展基础】、GUI

【C语言】如何产生正态分布或高斯分布随机数
![[C language] about scanf() and scanf_ Some problems of s()](/img/d1/e3d0b845e699c8c1fe3eb9f3b250e1.png)
[C language] about scanf() and scanf_ Some problems of s()

【C语言】二叉树的实现及三种遍历
随机推荐
【Unity编辑器扩展基础】、EditorGUILayout (三)
EMC RS485接口EMC电路设计方案
不到一小时,苹果摧毁了15家初创公司
fatal: unsafe repository (‘/home/anji/gopath/src/gateway‘ is owned by someone else)
[vi/vim] basic usage and command summary
女子高考落榜读专科逆袭买千万别墅,考得不好真的没关系
AGCO AI frontier promotion (2.16)
【Unity编辑器扩展实践】、查找所有引用该图片的预制体
URL append parameter method, considering #$ Situation of
AcWing 604. Area of circle (implemented in C language)
Privilege management of vivo mobile phone
Prepare for Jin San Yin Si I. testers without experience in automated testing projects should look at it quickly
Unity导入资源后还手动修改资源的属性?这段代码可以给你节约很多时间:AssetPostprocessor
【Unity编辑器扩展基础】、GUI
双缓冲绘图
Setting overridesorting for canvas does not take effect
UGUI使用小技巧(六)Unity实现字符串竖行显示
Is there a threshold for opening futures accounts? How to open futures accounts safely on the Internet
RemoteViews布局和类型限制源码分析
模板_大整数乘法