gpt4 book ai didi

unity3d - 如何在 RectTransform 中计算 sizeDelta?

转载 作者:行者123 更新时间:2023-12-04 00:08:34 26 4
gpt4 key购买 nike

我编写了自定义布局所需的自定义内容拟合器。所以,我需要控制 RectTransform.sizeDelta当 anchor 不同时的属性,但我无法得到显示此值的属性。
我不需要 Unity3D API 引用,我读了它并没有得到任何东西,因为它只说:

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.



谁能用普通语言解释一下这是什么意思?当 anchor 不同时,我如何手动计算它?

最佳答案

这个定义确实有点令人困惑。
sizeDelta ,基本上,返回 UI 元素的实际矩形与 anchor 定义的矩形之间的差异。

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

anchor 定在与矩形角相同的位置:sizeDelta是 (0,0)
enter image description here

矩形一半宽度处的左 anchor 或右 anchor :sizeDelta是 (150,0)
enter image description here
enter image description here

一个点中的所有四个 anchor :sizeDelta是 (300,200)(即:与矩形大小相同)
enter image description here
enter image description here

如您所见, anchor 定义的矩形的中心在哪里根本无关紧要,唯一重要的是元素矩形和 anchor 矩形的宽度和高度之间的差异。

在伪代码中,它是这样的:

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

因此,如果 UI 矩形的尺寸大于 anchor 的尺寸, sizeDelta为正,如果较小,则 sizeDelta是否定的。

关于unity3d - 如何在 RectTransform 中计算 sizeDelta?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44471568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com