forked from unity3d-jp/UnityChanSpringBone
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetObjectParentWindow.cs
More file actions
executable file
·52 lines (44 loc) · 1.64 KB
/
SetObjectParentWindow.cs
File metadata and controls
executable file
·52 lines (44 loc) · 1.64 KB
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
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEditor.Localization.Editor;
namespace Unity.Animations.SpringBones
{
public class SetObjectParentWindow : EditorWindow
{
private static class Styles
{
public static readonly string editorWindowTitle = Localization.Tr("Parenting Tool");
public static readonly GUIContent labelNewParent = new GUIContent(Localization.Tr("New Parent"));
public static readonly GUIContent labelSetParent = new GUIContent(Localization.Tr("Set Parent"));
}
[MenuItem("Window/Animation/SpringBone/Parenting Tool")]
public static void ShowWindow()
{
GetWindow<SetObjectParentWindow>(Styles.editorWindowTitle);
}
// private
private Transform newParent;
private void ReparentSelectedObjects()
{
var newChildren = Selection.gameObjects
.Where(item => item.transform != newParent)
.Select(gameObject => gameObject.transform)
.ToArray();
foreach (var child in newChildren)
{
Undo.SetTransformParent(child, newParent, "Set Parent");
}
}
private void OnGUI()
{
EditorGUILayout.Space();
newParent = EditorGUILayout.ObjectField(Styles.labelNewParent, newParent, typeof(Transform), true) as Transform;
EditorGUILayout.Space();
if (GUILayout.Button(Styles.labelSetParent))
{
ReparentSelectedObjects();
}
}
}
}