From b49dd4e9180cc277c8b1fbc92c859210ce88ed1e Mon Sep 17 00:00:00 2001 From: c0ffeeartc Date: Fri, 22 May 2020 03:13:47 +0300 Subject: [PATCH] Added undo to uGUITools.AnchorsToCorners, uGUITools.CornersToAnchors --- Editor/uGUITools.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) mode change 100644 => 100755 Editor/uGUITools.cs diff --git a/Editor/uGUITools.cs b/Editor/uGUITools.cs old mode 100644 new mode 100755 index a3fb414..f64bd48 --- a/Editor/uGUITools.cs +++ b/Editor/uGUITools.cs @@ -9,9 +9,18 @@ namespace UnityEngine.UI.Extensions [MenuItem("uGUI/Anchors to Corners %[")] static void AnchorsToCorners() { + if (Selection.transforms == null || Selection.transforms.Length == 0) + { + return; + } + Undo.IncrementCurrentGroup(); + Undo.SetCurrentGroupName("AnchorsToCorners"); + var undoGroup = Undo.GetCurrentGroup(); + foreach (Transform transform in Selection.transforms) { RectTransform t = transform as RectTransform; + Undo.RecordObject( t, "AnchorsToCorners" ); RectTransform pt = Selection.activeTransform.parent as RectTransform; if (t == null || pt == null) return; @@ -25,19 +34,30 @@ namespace UnityEngine.UI.Extensions t.anchorMax = newAnchorsMax; t.offsetMin = t.offsetMax = new Vector2(0, 0); } + Undo.CollapseUndoOperations(undoGroup); } [MenuItem("uGUI/Corners to Anchors %]")] static void CornersToAnchors() { + if (Selection.transforms == null || Selection.transforms.Length == 0) + { + return; + } + Undo.IncrementCurrentGroup(); + Undo.SetCurrentGroupName("CornersToAnchors"); + var undoGroup = Undo.GetCurrentGroup(); + foreach (Transform transform in Selection.transforms) { RectTransform t = transform as RectTransform; + Undo.RecordObject( t, "CornersToAnchors" ); if (t == null) return; t.offsetMin = t.offsetMax = new Vector2(0, 0); } + Undo.CollapseUndoOperations(undoGroup); } [MenuItem("uGUI/Mirror Horizontally Around Anchors %;")]