-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathAnchorToolsEditor.cs
More file actions
38 lines (28 loc) · 997 Bytes
/
AnchorToolsEditor.cs
File metadata and controls
38 lines (28 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using UnityEditor;
using UnityEngine;
public class UIAnchors {
[MenuItem("SUI/Set Anchors To Corner %U")]
static void AnchorsToCorner()
{
EditorGUI.BeginChangeCheck();
Undo.RecordObjects(Selection.transforms,"Changed UI anchors");
foreach (Transform transform in Selection.transforms) {
RectTransform t = transform as RectTransform;
RectTransform pt = Selection.activeTransform.parent as RectTransform;
if (t == null || pt == null) return;
Vector2 newAnchorsMin = new Vector2(t.anchorMin.x + t.offsetMin.x / pt.rect.width,
t.anchorMin.y + t.offsetMin.y / pt.rect.height);
Vector2 newAnchorsMax = new Vector2(t.anchorMax.x + t.offsetMax.x / pt.rect.width,
t.anchorMax.y + t.offsetMax.y / pt.rect.height);
t.anchorMin = newAnchorsMin;
t.anchorMax = newAnchorsMax;
t.offsetMin = t.offsetMax = new Vector2(0, 0);
}
}
}
/*
__ _ _____ ____ _ _____
| \| | __\ `v' / \| |_ _|
| | ' | _| `. .'| | ' | | |
|_|\__|_| !_! |_|\__| |_|
*/