An easy-to-understand detailed explanation of Unity anchor points Anchors

1. What is the anchor point Anchors

When you create a child object under Canvas, the selected child object will have four △, as follows

This triangle can also be separated, as follows

It is worth mentioning that these four triangles can only form a rectangle, or a point, for example (rectangle)

It is impossible for you to make it into another shape, such as a parallelogram, if you don't believe me, try it.

Since we can't make it look different, we can only control the position of these four sides to change the size of the rectangle

2. Use data to change the anchor point Anchors

This rectangle is drawn on the parent object, so we must have the parent object

If the black in the picture below is the parent object, we draw four lines on it (these four lines are all parallel to the edge)

Just need to draw four lines, I can make a rectangle (the white part)

Then, I only need to change the position of these four lines, and I can make different rectangles

Red line, yellow line only need to move left and right

Green line, blue line just need to move up and down 

Next, in order to know the specific position of this line, I put a coordinate system in

We go ahead and give each edge a function:

The red line represents the left side of the rectangle and can only move left and right, so it is called x, which is closer to the 0 point of x, so it is called small x (minX)

The yellow line represents the right side of the rectangle and can only move left and right, so it is called x, which is closer to 1 point of x, so it is called big x (maxX)

The blue line represents the lower side of the rectangle and can only move up and down, so it is called y, which is closer to the 0 point of y, so it is called small y (minY)

The green line represents the upper side of the rectangle and can only move up and down, so it is called y, which is closer to 1 point of y, so it is called big y (maxY)

on the contrary:

If you want to move the red line, adjust minX

If you want to move the yellow line, adjust maxX

If you want to move the blue line, adjust minY

If you want to move the green line, adjust maxY

Finally: we look at the panel, the data on the panel is clear at a glance

3. The position of the anchor point will change with the size of the parent object

Because the position of the triangle can only be written between 0 and 1, it actually means the percentage of the x or y axis of the parent object.

After the triangle is set, the size of the parent object changes, and the position of the triangle also changes.

(This piece will not be explained in detail, it should be understood by everyone)

4. The role of anchors Anchors (when the anchor points are separated)

 This rectangle is to determine where the four corners are, what is useful is not the rectangle, but the four corners

These four corners are used to bind sub-objects

I first put a child object in, and then adjust the four corners

Then imagine a scene with me, the four corners of the child object are tied to the four triangles with non-elastic sticks

If the length of the stick is fixed and cannot be changed, what will happen if our triangle changes its position?

It will squeeze the picture flat or pull it apart, which is the role of the anchor point, in order to let the child object adapt to the shape and position of the parent object

 5. The role of anchors Anchors (when the anchors are together)

At this time, the four corners of the child object are tied to one point

At this time, if the parent object is changed, the point will only move, and the child object will move accordingly, without squeezing the child object

(If you don't understand, you can imagine that your hands and feet are tied to a pole. If the pole moves, you will only move with it, and you will not become flat)

 Therefore, the anchor point at this time can adapt to the specific position of the child object according to the specific position of the parent object.

Here's what it looks like when moving at the above anchor position

 6. If it is not detailed enough, you can ask questions in the comment area, and I will continue to update

Here is a favorite fan Up, thank you for your attention

 

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_49427945/article/details/131803086