private static void MoveAnchorsToCorners(RectTransform ownRectTransform, RectTransform parentRectTransform, Rect anchorRect)
{
Vector2 anchorVector = Vector2.zero;
float pivotX = anchorRect.width * ownRectTransform.pivot.x;
float pivotY = anchorRect.height * (1 - ownRectTransform.pivot.y);
ownRectTransform.anchorMin = new Vector2(0f, 1f);
ownRectTransform.anchorMax = new Vector2(0f, 1f);
float offsetMinX = anchorRect.x / ownRectTransform.localScale.x;
float offsetMinY = anchorRect.y / ownRectTransform.localScale.y - anchorRect.height;
ownRectTransform.offsetMin = new Vector2(offsetMinX, offsetMinY);
float offsetMaxX = anchorRect.x / ownRectTransform.localScale.x + anchorRect.width;
float offsetMaxY = anchorRect.y / ownRectTransform.localScale.y;
ownRectTransform.offsetMax = new Vector2(offsetMaxX, offsetMaxY);
float anchorMinX = ownRectTransform.anchorMin.x + anchorVector.x + (ownRectTransform.offsetMin.x - pivotX) / parentRectTransform.rect.width * ownRectTransform.localScale.x;
float anchorMinY = ownRectTransform.anchorMin.y - (1 - anchorVector.y) + (ownRectTransform.offsetMin.y + pivotY) / parentRectTransform.rect.height * ownRectTransform.localScale.y;
ownRectTransform.anchorMin = new Vector2(anchorMinX, anchorMinY);
float anchorMaxX = ownRectTransform.anchorMax.x + anchorVector.x + (ownRectTransform.offsetMax.x - pivotX) / parentRectTransform.rect.width * ownRectTransform.localScale.x;
float anchorMaxY = ownRectTransform.anchorMax.y - (1 - anchorVector.y) + (ownRectTransform.offsetMax.y + pivotY) / parentRectTransform.rect.height * ownRectTransform.localScale.y;
ownRectTransform.anchorMax = new Vector2(anchorMaxX, anchorMaxY);
offsetMinX = (0 - ownRectTransform.pivot.x) * anchorRect.width * (1 - ownRectTransform.localScale.x);
offsetMinY = (0 - ownRectTransform.pivot.y) * anchorRect.height * (1 - ownRectTransform.localScale.y);
ownRectTransform.offsetMin = new Vector2(offsetMinX, offsetMinY);
offsetMaxX = (1 - ownRectTransform.pivot.x) * anchorRect.width * (1 - ownRectTransform.localScale.x);
offsetMaxY = (1 - ownRectTransform.pivot.y) * anchorRect.height * (1 - ownRectTransform.localScale.y);
ownRectTransform.offsetMax = new Vector2(offsetMaxX, offsetMaxY);
}
这一段代码的作用是什么 |