RectTransform探索

anchoredPosition

The position of the pivot of this RectTransform relative to the anchor reference point.

anchoredPosition3D

The 3D position of the pivot of this RectTransform relative to the anchor reference point.

anchorMax

The normalized position in the parent RectTransform that the upper right corner is anchored to.

anchorMin

The normalized position in the parent RectTransform that the lower left corner is anchored to.

offsetMax

The offset of the upper right corner of the rectangle relative to the upper right anchor.

offsetMin

The offset of the lower left corner of the rectangle relative to the lower left anchor.

pivot

The normalized position in this RectTransform that it rotates around.

rect

The calculated rectangle in the local space of the Transform.

sizeDelta

The size of this RectTransform relative to the distances between the anchors.

 

  • anchor:连接Parent与Child的纽带。分为: anchor为点(即anchorMin == anchorMax),anchor为矩形框。

anchor为点:Pos相对于自身锚框的X和Y。 即相对于Parent位置固定(因此Parent大小变化不会导致自身位置变化,锚点保持和Parent元素的中心点位置不变。)anchor为框:即相对于Parent框的位置固定(因此Parent大小变化会导致自身发生变化,锚框根据Parent元素发生变化,保持相对Partent的元素的锚框比例发生不变)。

  • Pivot 中心点:
  • offsetMax; 矩形右上角(显示的元素)相对于右上角锚点(或锚框右上角)的偏移量。
  • offsetMin; 矩形右上角(显示的元素)相对于左下角锚点(或锚框左上角)的偏移量。
  • sizeDelta: RectTransform的大小相对于锚点之间的距离
  1. sizeDelta = offsetMax - offsetMin。使用代码中的offsetMax - offsetMax即可得出。
  2. 因此sizeDelta的含义也是变化的。
public Vector2 offsetMin
{
get
{
return anchoredPosition - Vector2.Scale(sizeDelta, pivot);
}
set
{
Vector2 offset = value - (anchoredPosition - Vector2.Scale(sizeDelta, pivot));
sizeDelta -= offset;
anchoredPosition += Vector2.Scale(offset, Vector2.one - pivot);
}
}

public Vector2 offsetMax
{
get
{
return anchoredPosition + Vector2.Scale(sizeDelta, Vector2.one - pivot);
}
set
{
Vector2 offset = value - (anchoredPosition + Vector2.Scale(sizeDelta, Vector2.one - pivot));
sizeDelta += offset;
anchoredPosition += Vector2.Scale(offset, pivot);
}
}
  • anchoredPosition:Pivot 相对于锚点(或者是锚框中心点)的位置。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值