# UIWidget align component
# Overview
UIWidget is the basic alignment component
, according to Target
and corresponding direction anchor point
, change the coordinates
, width and height
of Transform2D associated with it.
# Static attribute description
Execute: The enumeration value of the timing of the update operation, corresponding to different component life cycles.
// engine.UIWidget.Execute
enum Execute {
onEnable, // onEnable stage
onUpdate, // onUpdate phase
onAwake, // onAwake stage
}
# Property description
Method | Parameters | Return Value | Function |
---|---|---|---|
execute | Execute | Execute.onUpdate | When the component properties or target associated properties change, the specific timing of the update operation. |
leftAnchorTarget | Transform2D | undefined | Left alignment target. |
leftAnchor | number / undefined | undefined | The anchor point of the bounding box of the left target content, as the starting point of the left alignment (value range (0-1)) |
leftOffset | number | 0 | The offset to be superimposed after the alignment operation of the target Anchor in the left direction |
rightAnchorTarget | Transform2D | undefined | Align the target in the right direction. |
rightAnchor | number / undefined | undefined | The anchor point of the bounding box of the right target content, as the starting point of the right alignment (value range (0-1)) |
rightOffset | number | 0 | The offset to be superimposed after aligning the target Anchor in the right direction |
topAnchorTarget | Transform2D | undefined | Align the target in the up direction. |
topAnchor | number / undefined | undefined | The anchor point of the bounding box of the upper target content, as the starting point of the upper alignment (value range (0-1)) |
topOffset | number | 0 | The offset to be superimposed after aligning the target Anchor in the upward direction |
bottomAnchorTarget | Transform2D | undefined | Align the target in the downward direction. |
bottomAnchor | number / undefined | undefined | The anchor point of the bounding box of the lower target content, as the starting point of the downward alignment (value range (0-1)) |
bottomOffset | number | 0 | The offset to be superimposed after aligning the target Anchor according to the downward direction |
# Target
attribute
leftAnchorTarget, rightAnchorTarget, topAnchorTarget, bottomAnchorTarget
# Target exists in any direction, locate according to Target
Targets in different directions can be different nodes on the field.
If the Target is set in the horizontal or vertical direction at the same time, the size of the Transform2D associated with the UIWidget will be modified according to the Target and the corresponding anchor point in the two directions to adapt the alignment position.
# If the Targets in the four directions are all empty, locate according to the parent element
The component will modify the size of the Transform2D associated with the UIWidget to adapt the alignment position according to the parent node information and the anchor points corresponding to the four directions.
# Notice
- In the solution tool, drag the entity node in the hierarchy manager to the Target property of the property inspector to bind the required components to the target. You can also set and modify the Target in the code.
- To cancel the alignment in a certain direction of the UIWidget, you need to set the Target or the corresponding anchor of the corresponding direction to undefined.
- When there are corresponding Anchor and target (Target or parent element) in the same direction, the alignment operation will be performed.
- The untargeted UIWidget hanging under UIRoot will be aligned according to the current two-dimensional world.