-
Notifications
You must be signed in to change notification settings - Fork 1
/
BatchMover.cs
107 lines (93 loc) · 2.91 KB
/
BatchMover.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using UnityEngine;
using UnityEditor;
public class BatchMover : EditorWindow
{
bool bReverseTranslate = false;
Vector3 translate = new Vector3();
bool bReverseRotate = false;
Vector3 rotate = new Vector3();
bool bReverseScale = false;
Vector3 scale = new Vector3(1, 1, 1);
[MenuItem("Window/Batch Mover")]
static void Awake()
{
GetWindow<BatchMover>().Show();
}
void OnGUI()
{
minSize = new Vector2(226, 226);
bReverseTranslate = EditorGUILayout.Toggle(new GUIContent("Reverse Translate", "Causes the translation to happen in reverse.\nBasically a simple method to Undo."), bReverseTranslate);
translate = EditorGUILayout.Vector3Field("Translate Distance", translate);
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("World Translate"))
{
BatchMove(bReverseTranslate ? -translate : translate, true);
}
if (GUILayout.Button("Local Translate"))
{
BatchMove(bReverseTranslate ? -translate : translate);
}
EditorGUILayout.EndHorizontal();
bReverseRotate = EditorGUILayout.Toggle(new GUIContent("Reverse Rotation", "Causes the rotation to happen in reverse.\nBasically a simple method to Undo."), bReverseRotate);
rotate = EditorGUILayout.Vector3Field("Rotation Amount", rotate);
if (GUILayout.Button("Rotate"))
{
BatchRotate(bReverseRotate ? -rotate : rotate);
}
bReverseScale = EditorGUILayout.Toggle(new GUIContent("Reverse Scale Mutlipler", "Causes the scale multiplication to happen in reverse.\nBasically a simple method to Undo. Only works on Multiply."), bReverseScale);
scale = EditorGUILayout.Vector3Field("Scale Multiplier", scale);
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Multiply Scale"))
{
BatchScale(bReverseScale ? new Vector3(1 / scale.x, 1 / scale.y, 1 / scale.z) : scale);
}
if (GUILayout.Button("Set Scale"))
{
BatchScale(scale, true);
}
EditorGUILayout.EndHorizontal();
}
void BatchMove(Vector3 amount, bool bWorldSpace = false)
{
Undo.RecordObjects(Selection.transforms, "Batch Move");
for (int i = 0; i < Selection.transforms.Length; ++i)
{
if (bWorldSpace)
{
Selection.transforms[i].Translate(amount, Space.World);
}
else
{
Selection.transforms[i].Translate(amount, Space.Self);
}
}
}
void BatchRotate(Vector3 amount)
{
Undo.RecordObjects(Selection.transforms, "Batch Rotate");
for (int i = 0; i < Selection.transforms.Length; ++i)
{
Selection.transforms[i].Rotate(amount);
}
}
void BatchScale(Vector3 amount, bool bSetScale = false)
{
Undo.RecordObjects(Selection.transforms, "Batch Scale");
for (int i = 0; i < Selection.transforms.Length; ++i)
{
if (bSetScale)
{
Selection.transforms[i].localScale = amount;
}
else
{
Selection.transforms[i].localScale = new Vector3
(
Selection.transforms[i].localScale.x * amount.x,
Selection.transforms[i].localScale.y * amount.y,
Selection.transforms[i].localScale.z * amount.z
);
}
}
}
}