Skip to content

Commit 1bd9aa4

Browse files
committed
Automatic detection of gui and 3d objects when changing positions
1 parent 4074502 commit 1bd9aa4

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

Editor/AdjustPosition.cs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,26 @@ internal static void Execute()
2424
if (ox != 0 || oy != 0)
2525
{
2626
evt.Use();
27-
28-
switch(Settings.OperatorMode)
27+
28+
var offset2 = new Vector2(ox, oy);
29+
var offset3 = new Vector3(ox, oy, 0);
30+
// shift change z for 3d
31+
if(evt.shift)
32+
offset3 = new Vector3(0, 0, ox + oy);
33+
if (evt.control)
34+
{
35+
offset2 *= 10;
36+
offset3 *= 10;
37+
}
38+
39+
foreach(var trans in Utils.GetTransforms())
2940
{
30-
case OperatorMode.UGUI:
31-
var offset = new Vector2(ox, oy);
32-
if (evt.control) offset *= 10;
33-
foreach (var rt in Utils.GetRectTransforms())
34-
{
35-
Undo.RecordObject(rt, "AdjustPosition");
36-
rt.anchoredPosition += offset;
37-
}
38-
break;
39-
case OperatorMode.World:
40-
if (evt.shift)
41-
{
42-
oz = ox + oy;
43-
ox = oy = 0;
44-
}
45-
var offset3 = new Vector3(ox, oy, oz);
46-
if (evt.control) offset3 *= 10;
47-
foreach (var rt in Utils.GetWorldTransforms())
48-
{
49-
Undo.RecordObject(rt, "AdjustPosition");
50-
rt.position += offset3;
51-
}
52-
break;
41+
Undo.RecordObject(trans, "AdjustPosition");
42+
if (trans is RectTransform)
43+
((RectTransform)trans).anchoredPosition += offset2;
44+
else
45+
trans.localPosition += offset3;
5346
}
54-
5547
}
5648
}
5749
}

Editor/Utils.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ internal static Texture LoadTexture(string textureName)
1515
return AssetDatabase.LoadAssetAtPath<Texture2D>(path);
1616
}
1717

18+
internal static Transform[] GetTransforms()
19+
{
20+
return Selection.transforms;
21+
}
22+
1823
internal static List<RectTransform> GetRectTransforms()
1924
{
2025
var arr = Selection.transforms;

0 commit comments

Comments
 (0)