public static void SetRectTransformAnchors(RectTransform rtf, AnchorType anchor, bool is_stay = false) { Vector2 anchors_min = new Vector2(); Vector2 anchors_max = new Vector2(); if (anchor < AnchorType.Full) { AnchorVerType ver_type = (AnchorVerType)((int)anchor / 3); AnchorHorType hor_type = (AnchorHorType)((int)anchor % 3); SetRectTransformAnchors(rtf, ver_type, hor_type, is_stay); return; } else if (anchor == AnchorType.Full) { anchors_min = new Vector2(0, 0); anchors_max = new Vector2(1, 1); } else if (anchor == AnchorType.StretchLeftAndRight) { anchors_min = new Vector2(0, 0.5f); anchors_max = new Vector2(1, 0.5f); } else if (anchor == AnchorType.StretchUpAndDown) { anchors_min = new Vector2(0.5f, 0); anchors_max = new Vector2(0.5f, 1); } if (is_stay) { StayPosition(rtf, anchors_min, anchors_max); } rtf.anchorMin = anchors_min; rtf.anchorMax = anchors_max; }
public static void SetRectTransformAnchors(RectTransform rtf, AnchorVerType ver_type, AnchorHorType hor_type, bool is_stay = false) { Vector2 anchors = Vector2.zero; switch (hor_type) { case AnchorHorType.Left: anchors.x = 0; break; case AnchorHorType.Center: anchors.x = 0.5f; break; case AnchorHorType.Right: anchors.x = 1; break; } switch (ver_type) { case AnchorVerType.Bottom: anchors.y = 0; break; case AnchorVerType.Center: anchors.y = 0.5f; break; case AnchorVerType.Top: anchors.y = 1; break; } if (is_stay) { StayPosition(rtf, anchors, anchors); } rtf.anchorMax = anchors; rtf.anchorMin = anchors; }