UGUI Manual

An official document Unity 5.5 for example

Canvas

UI elements before and after the order: SetAsFirstSibling, SetAsLastSibling, and SetSiblingIndex

BasicLayout

Documentation: https://docs.unity3d.com/Manual/UIBasicLayout.html

Anchor use, may be with respect to the parent node, such as the Anchor Left, four triangle is on the left

image

image

Layout element (LayoutElement)

LayoutElement not directly modify the size of elements, but provides information for Layout Controller

On a gameobject bound Rect Transform can be called LayoutElement

Image and Text provides the Preferred width and height in the properties panel

You can add Layout Element assembly to rewrite Min, Preferred, Flexible size

image

Layout Control (Layout Controller)

Documentation: https://docs.unity3d.com/Manual/UIAutoLayout.html

Layout Element Layout group's size in seeking compliance with the following principles:

  • First, Min Size is assigned
  • If there is enough space, Preferred Size (priority size) will be allocated
  • If there is extra space, Flexible Size (elastic, flexible) will be assigned

 

Those are the Layout Controller?

Content Size Fitter (content)

Aspect Ratio Fitter (aspect ratio, aspect ratio)

Layout Groups (horizontal, vertical, the Grid)

 

Layout calculation

Automatic layout system layout evaluation and implementation in the following order:

1. Min, Preferrd, Flexible width calculated by ILayoutElement. CalculateLayoutInputHorizontal, which is performed in the order from bottom to top, first calculates a ratio Parent Child, so that the information will be considered when calculating Parent to Child

2. Effect of the effective width of the layout element by ILayoutController.SetLayoutHorizontal, perform a top-down order, calculates the ratio of the Child Parent, Child because that the width of the distribution Parent, then modify the new width RectTransform

3. Min, Preferrd, Flexible height by ILayoutElement.CalculateLayoutInputVertical, which is performed in the order from bottom to top, first calculates a ratio Parent Child, so that the information will be considered when calculating Parent to Child

4. The effective height layout element by sequentially ILayoutController.SetLayoutVertical, performed from top to bottom, after calculating Child Parent, Child is because the height distribution is characterized Parent, and then modify the new height of RectTransform

As can be seen from the above automatic layout system to evaluate the width and height of the evaluation, so the height calculation may depend on the width, but the width can not calculate the height independent.

Thoughts: first calculate the width, and then calculate the effective width?

 

Trigger layout reconstruction

When a property of a component changes can lead to failure of the current layout, the layout needs to be rebuilt, triggered by calling the following:

LayoutRebuilder.MarkLayoutForRebuild (transform as RectTransform);

Reconstruction will not take effect immediately, it will take effect before the end of the current frame rendering. The reason is not directly in effect: if the number of reconstruction in the same frame, can degrade performance.

Reconstruction should be triggered in the following situations:

  • In setters for properties that can change the layout.

In these callbacks: In the following the callback function

  • OnEnable
  • OnDisable
  • OnRectTransformDimensionsChange
  • OnValidate (only needed in the editor, not at runtime)
  • OnDidApplyAnimationProperties

Guess you like

Origin www.cnblogs.com/zhaoqingqing/p/6291260.html