如何在RectTransform中计算sizeDelta?

如何在RectTransform中计算sizeDelta?

问题描述:

我编写了自定义布局所需的自定义内容筛选器.因此,当锚点不相同但我无法显示该值时,我需要控制RectTransform.sizeDelta属性.
我不需要 Unity3D API 参考,我读了一下却没有任何提示,因为它只说:

I write a custom content fitter that is required for my custom layout. So, I need to control RectTransform.sizeDelta property when anchors aren't same but I can't get that shows this value.
I don't need Unity3D API reference, I read it and got a nothing cuz it says only:

此RectTransform的大小相对于 锚点.如果锚点在一起,则sizeDelta与size相同. 如果锚点位于父级的四个角中的每个角上,则 sizeDelta是与矩形相比要放大或缩小的大小 它的父母.

The size of this RectTransform relative to the distances between the anchors. If the anchors are together, sizeDelta is the same as size. If the anchors are in each of the four corners of the parent, the sizeDelta is how much bigger or smaller the rectangle is compared to its parent.

任何人都可以用普通语言解释这是什么意思吗?当锚点不相同时,我该如何手动计算?

Can anyone explain in normal language what does it mean? And how can I calculate it manually when anchors aren't same?

的定义确实有些混乱.

sizeDelta基本上返回UI元素的实际矩形与锚点定义的矩形之间的差.

sizeDelta, basically, returns the difference between the actual rectangle of the UI element and the rectangle defined by the anchors.

例如,给定一个300x200的矩形:

For example, given a rectangle of 300x200:

与矩形角在同一位置的锚点:sizeDelta为(0,0)

Anchors in the same place as the corners of the rectangle: sizeDelta is (0,0)

在矩形的一半宽度处的左或右锚点:sizeDelta为(150,0)

Left or right anchors at half width of the rectangle: sizeDelta is (150,0)

一个点上的所有四个锚点:sizeDelta为(300,200)(即:与矩形大小相同)

All four anchors in a point: sizeDelta is (300,200) (i.e.: same size as the rectangle)

您可以看到,锚点定义的矩形的中心哪里根本不重要,唯一重要的是元素的宽度和高度之间的差异矩形和锚矩形.

As you can see, it doesn't matter at all where the center of the rectangle defined by the anchors is, the only thing that matters is the difference between the width and height of the element rectangle and the anchors rectangle.

在伪代码中,是这样的:

In pseudo-code, it's like this:

sizeDelta.x = UIElementRectangle.width - AnchorsRectangle.width;
sizeDelta.y = UIElementRectangle.height - AnchorsRectangle.height;

因此,如果UI矩形的尺寸大于锚点的尺寸,则sizeDelta为正,如果较小,则sizeDelta为负.

So, if the UI Rectangle has a dimension bigger than the anchors' one, sizeDelta is positive, if it's smaller, sizeDelta is negative.