current position：Home>Unity zero foundation to advanced [UI system learning] ugui layout element introduction and simple example
Unity zero foundation to advanced [UI system learning] ugui layout element introduction and simple example
2021-08-22 22:38:21 【Silly little y Typing Code】
- The last article introduced Content Size Fitter（ Content Resizer ）
- Let's talk about this blog UGUI Layout elements Layout Element
- Including an official introduction and an example demonstration
????Layout Element Introduction to layout elements
The official introduction ： If you want to override the minimum, preferred, or flexible size of a layout element, you can do that by adding a Layout Element component to the GameObject. A layout controller allocates width or height to a layout element in the following order:
- First, the layout controller allocates the minimum size properties (Min Width, Min Height).
- If there is sufficient available space, the layout controller allocates the preferred size properties (Preferred Width, Preferred Height).
- If there is additional available space, the layout controller allocates the flexible size properties (Flexible Width, Flexible Height).
translate ： If you want to override the minimum of layout elements 、 Preferred or flexible size , You can do this by adding layout element components to the game object . The layout controller assigns width or height to layout elements in the following order ：
- First , The layout controller assigns the minimum size attribute （Min Width,Min Height）.
- If there is enough free space , The layout controller assigns the preferred size attribute （Preferred Width、Preferred Height）.
- If there is additional free space , The layout controller assigns flexible size attributes （ Flexible width 、 Flexible height ）.
When enabled, the layout system ignores this layout element.
The minimum width this layout element should have.
The minimum height this layout element should have.
The preferred width this layout element should have before additional available width is allocated.
The preferred height this layout element should have before additional available height is allocated.
The relative amount of additional available width this layout element should fill out relative to its siblings.
The relative amount of additional available height this layout element should fill out relative to its siblings.
The layout priority for this component. If a GameObject has more than one component with layout properties (for example, an Image component and a LayoutElement component), the layout system uses the property values from the component with the highest Layout Priority.If the components have the same Layout Priority, the layout system uses the highest value for each property, regardless of which component it comes from.
- Ignore Layout Ignore layout ： When enabled , The layout system ignores this layout element .
- Min Width Minimum width ： The minimum width that this layout element should have .
- Min Height Minimum height ： The minimum height that this layout element should have .
- Preferred Width Preferred width ： Before allocating additional available width , The preferred width that this layout element should have .
- Preferred Height Preferred height ： Before allocating additional available heights , The preferred height that this layout element should have .
- Flexible Width Flexible width ： The relative amount of extra available width that this layout element should fill relative to its sibling elements .
- Flexible Height Flexible height ： The relative amount of additional available height that this layout element should fill relative to its sibling elements .
- Layout Priority Layout first ： The layout priority of this component . If one GameObject There are multiple components with layout properties （ for example , One Image Components and a LayoutElement Components ）, The layout system uses data from the highest Layout Priority Property value of the component . If the components have the same Layout Priority, Then the layout system is each Attributes use the highest value , No matter which component it comes from .
Layout elements include 7 Attributes , The top 6 The first attribute is the setting of the size information of each layout element , It is generally used for layout controller to set its size and position .
- Layout There are two core elements involved , Including layout controller （Layout Controller） And layout elements , The layout controller includes a horizontal layout group 、 Vertical layout group and grid layout group ; Layout elements （Layout Element） It's those with Rect Transform The object of the component , Not just those with Layout Element The object of the component .
- Layout elements do not change their size , Instead, the layout controller controls the layout according to the size attributes of the layout elements （ Minimum width and height （ Set according to the pixel size ）、 The most suitable width and height （ Set according to the pixel size ）、 Retractable width and height （ Set according to weight ）） To assign the corresponding size and location . Layout group （ Layout controller ） Will meet the minimum size of all layout elements .
- Flexible Width and Flexible Height Is to set the expansion size by weight , That is, if the layout group has configured the most suitable width and height of all layout elements, there is still space left , The remaining controls will be allocated the remaining space according to the scalable control weight of each layout element .
- Ignore Layout, That is, this layout element does not participate in the layout of the layout group .
- Text （Text） And images （Image） default Preferred Width and Height Are the number and size of text and pictures .
????Layout Element Examples of use
- What I use in this component at present is Ignore Layout
- When an object uses a layout controller , The position of subclasses cannot be changed
- Then we can add... To a child object Layout Element
- This is the time , This sub object is no longer affected by the layout controller , Free placement
- This function is easy to use in some special cases , Here's a demonstration , Look at the effect
Example ： There is an object Panel Added Grid Layout Group Grid layout controller , It has three sub objects
because Grid Layout Group Is to lock the size and position of sub objects , Therefore, changing the size of sub objects will not change at this time
But we add... To one of the child objects Layout Element , And check the Ignore Layout after , The child object is out of control of the parent object
And you can freely control the size and position , Completely free ！
The content of this article is for UGUI Medium Layout elements Layout Element A simple introduction and use example
This component has many more uses , Here is just a super simple usage
Because I haven't met a good need to use this component at present , So let's briefly introduce these , In the future, we will continue to fill the pit ！
Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .
author[Silly little y Typing Code],Please bring the original link to reprint, thank you.
The sidebar is recommended
- Crazy blessing! Tencent boss's "million JVM learning notes", real topic of Huawei Java interview 2020-2021
- How to implement injection in vuex source code?
- JQuery operation select (value, setting, selected)
- An article disassembles the pyramid architecture behind the gamefi outbreak
- BEM - a front-end CSS naming methodology
- [vue3] encapsulate custom global plug-ins
- Error using swiper plug-in in Vue
- Another ruthless character fell by 40000, which was "more beautiful" than Passat and maiteng, and didn't lose BMW
guess what you like
Huang Lei basks in Zhang Yixing's album, and the relationship between teachers and apprentices is no less than that in the past. Netizens envy Huang Lei
He was cheated by Wang Xiaofei and Li Chengxuan successively. Is an Yixuan a blessed daughter and not a blessed home?
Zhou Shen sang the theme song of the film "summer friends and sunny days" in mainland China. Netizen: endless aftertaste
Pink is Wangyuan online! Back to the peak! The new hairstyle is creamy and sassy
Front end interview daily 3 + 1 - day 858
Spring Webflux tutorial: how to build reactive web applications
[golang] walk into go language lesson 24 TCP high-level operation
August 23, 2021 Daily: less than three years after its establishment, Google dissolved the health department
The female doctor of Southeast University is no less beautiful than the female star. She has been married four times, and her personal experience has been controversial
There are many potential safety hazards in Chinese restaurant. The top of the program recording shed collapses, and the artist will fall down if he is careless
- Anti Mafia storm: He Yun's helpless son, Sun Xing, is destined to be caught by his dry son
- Introduction to flex flexible layout in CSS -- learning notes
- CSS learning notes - Flex layout (Ruan Yifeng tutorial summary)
- Today, let's talk about the arrow function of ES6
- Some thoughts on small program development
- Talk about mobile terminal adaptation
- Unwilling to cooperate with Wang Yibo again, Zhao Liying's fans went on a collective strike and made a public apology in less than a day
- JS function scope, closure, let, const
- Zheng Shuang's 30th birthday is deserted. Chen Jia has been sending blessings for ten years. Is it really just forgetting to make friends?
- Unveil the mystery of ascension
- Asynchronous solution async await
- Analysis and expansion of Vue infinite scroll source code
- Compression webpack plugin first screen loading optimization
- Specific usage of vue3 video play plug-in
- "The story of huiyeji" -- people are always greedy, and fairies should be spotless!
- Installing Vue devtool for chrome and Firefox
- Basic usage of JS object
- Two easy-to-use animation JS that make the page move
- Front end Engineering - scaffold
- Java SQL Server intelligent fixed asset management, back end + front end + mobile end
- Array de duplication problem solution - Nan recognition problem
- New choice for app development: building mobile applications using Vue native
- New gs8 Chengdu auto show announces interior Toyota technology blessing
- Vieira officially terminated his contract and left the team. The national security club sent blessings to him
- Less than 200000 to buy a Ford RV? 2.0T gasoline / diesel power, horizontal bed / longitudinal bed layout can be selected
- How does "heart 4" come to an end? Pinhole was boycotted by the brand, Ma Dong deleted the bad comments, and no one blessed him
- We are fearless in epidemic prevention and control -- pay tribute to the front-line workers of epidemic prevention!
- Front end, netty framework tutorial
- Xiaomi 11 | miui12.5 | android11 solves the problem that the httpcanary certificate cannot be installed
- The wireless charging of SAIC Roewe rx5 plus is so easy to use!
-  typescript
- CSS transform Complete Guide (Second Edition) flight.archives 007
- Ajax foundation - HTTP foundation of interview essential knowledge
- Cloud lesson | explain in detail how Huawei cloud exclusive load balancing charges
- [JS] 10. Closure application (loop processing)
- Left hand IRR, right hand NPV, master the password of getting rich