Merged in c0ffeeartc/unity-ui-extensions (pull request #70)

Added undo to uGUITools.AnchorsToCorners, uGUITools.CornersToAnchors
pull/413/head
c0ffee 2020-05-22 09:39:23 +00:00 committed by Simon Jackson
commit 59b184d627
1 changed files with 20 additions and 0 deletions

20
Editor/uGUITools.cs Normal file → Executable file
View File

@ -9,9 +9,18 @@ namespace UnityEngine.UI.Extensions
[MenuItem("uGUI/Anchors to Corners %[")] [MenuItem("uGUI/Anchors to Corners %[")]
static void AnchorsToCorners() 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) foreach (Transform transform in Selection.transforms)
{ {
RectTransform t = transform as RectTransform; RectTransform t = transform as RectTransform;
Undo.RecordObject( t, "AnchorsToCorners" );
RectTransform pt = Selection.activeTransform.parent as RectTransform; RectTransform pt = Selection.activeTransform.parent as RectTransform;
if (t == null || pt == null) return; if (t == null || pt == null) return;
@ -25,19 +34,30 @@ namespace UnityEngine.UI.Extensions
t.anchorMax = newAnchorsMax; t.anchorMax = newAnchorsMax;
t.offsetMin = t.offsetMax = new Vector2(0, 0); t.offsetMin = t.offsetMax = new Vector2(0, 0);
} }
Undo.CollapseUndoOperations(undoGroup);
} }
[MenuItem("uGUI/Corners to Anchors %]")] [MenuItem("uGUI/Corners to Anchors %]")]
static void CornersToAnchors() 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) foreach (Transform transform in Selection.transforms)
{ {
RectTransform t = transform as RectTransform; RectTransform t = transform as RectTransform;
Undo.RecordObject( t, "CornersToAnchors" );
if (t == null) return; if (t == null) return;
t.offsetMin = t.offsetMax = new Vector2(0, 0); t.offsetMin = t.offsetMax = new Vector2(0, 0);
} }
Undo.CollapseUndoOperations(undoGroup);
} }
[MenuItem("uGUI/Mirror Horizontally Around Anchors %;")] [MenuItem("uGUI/Mirror Horizontally Around Anchors %;")]