public static void CenterAnchor(RectCorner corner = RectCorner.UP_LEFT) { int undoID = MonkeyEditorUtils.CreateUndoGroup("Mirror Anchors"); foreach (Transform transform in Selection.transforms) { RectTransform t = transform as RectTransform; RectTransform pt = t != null ? t.parent as RectTransform : null; if (t == null || pt == null) { return; } Undo.RecordObject(t, "Mirror"); Undo.RecordObject(transform, "Mirror t"); Vector2 previousMax = t.anchorMax; switch (corner) { case RectCorner.UP_RIGHT: t.anchorMin = Vector2.one - t.anchorMax; break; case RectCorner.UP_LEFT: t.anchorMax = new Vector2(1 - t.anchorMin.x, t.anchorMax.y); t.anchorMin = new Vector2(t.anchorMin.x, 1 - previousMax.y); break; case RectCorner.BOTTOM_RIGHT: t.anchorMax = new Vector2(t.anchorMax.x, 1 - t.anchorMin.y); t.anchorMin = new Vector2(1 - previousMax.x, t.anchorMin.y); break; case RectCorner.BOTTOM_LEFT: t.anchorMax = Vector2.one - t.anchorMin; break; default: throw new ArgumentOutOfRangeException(nameof(corner), corner, null); } } Undo.CollapseUndoOperations(undoID); }
public static PointDouble GetCorner(this RectDouble rect, RectCorner corner) { switch (corner) { case RectCorner.TopLeft: return(rect.TopLeft); case RectCorner.TopRight: return(rect.TopRight); case RectCorner.BottomLeft: return(rect.BottomLeft); case RectCorner.BottomRight: return(rect.BottomRight); } ExceptionUtil.ThrowInvalidEnumArgumentException <RectCorner>(corner, "corner"); return(new PointDouble()); }
public static IEnumerable <(int x, int y)> DiagonalIndices(int width, int height, RectCorner entryPoint) { for (int i = 0; i <= width + height - 2; i++) { int x = 0, y = 0; switch (entryPoint) { case RectCorner.XMinYMin: x = Math.Max(0, i - (height - 1)); y = i - x; break; case RectCorner.XMaxYMax: x = Math.Max(0, width - 1 - i); y = (width + height - 2) - i - x; break; case RectCorner.XMinYMax: x = Math.Max(i - (height - 1), 0); y = x + height - 1 - i; break; case RectCorner.XMaxYMin: x = Math.Max(width - 1 - i, 0); y = x - (width - 1) + i; break; } while (0 <= x && x < width && 0 <= y && y < height) { yield return(x, y); switch (entryPoint) { case RectCorner.XMinYMin: case RectCorner.XMaxYMax: x++; y--; break; case RectCorner.XMinYMax: case RectCorner.XMaxYMin: x++; y++; break; } } } }