Tanoda
SoxAtkAnimPoseCopyPaste.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEditor;
3
4// 툴 목적 : 프리팹이나 게임오브젝트의 애니메이션할 때의 임시 포즈를 기본 상태에 적용하기 위한 툴.
5// 서로 다른 오브젝트간의 트랜스폼을 Copy & Paste 할 때에도 유용하다.
7{
8 private static Transform[] m_objs;
9 private static Vector3[] m_positions;
10 private static Quaternion[] m_rotations;
11 private static Vector3[] m_scales;
12
13 [MenuItem("GameObject/SoxATK/AnimPose/Copy with Children", false, 12)]
14 static void AnimPoseCopy()
15 {
16 // 루트 노드 하나만 선택된 상태에서만 작동한다.
17 // (Validate 함수가 없을 때 만든 검사라서 굳이 필요 없긴 하지만 일단 그대로 둠)
18 if (Selection.gameObjects.Length != 1)
19 {
20 EditorUtility.DisplayDialog("Anim pose Copy & Paste", "Please select one object", "OK");
21 return;
22 }
23
24 m_objs = Selection.activeGameObject.GetComponentsInChildren<Transform>();
25 m_positions = new Vector3[m_objs.Length];
26 m_rotations = new Quaternion[m_objs.Length];
27 m_scales = new Vector3[m_objs.Length];
28
29 for (int i = 0; i < m_objs.Length; i++)
30 {
31 m_positions[i] = m_objs[i].localPosition;
32 m_rotations[i] = m_objs[i].localRotation;
33 m_scales[i] = m_objs[i].localScale;
34 }
35 }
36
37 [MenuItem("GameObject/SoxATK/AnimPose/Copy with Children", true)]
38 static bool ValidateAnimPoseCopy()
39 {
40 return (Selection.gameObjects.Length == 1);
41 }
42
43 [MenuItem("GameObject/SoxATK/AnimPose/Paste with Children", false, 12)]
44 private static void AnimPosePaste()
45 {
46 // 루트 노드 하나만 선택된 상태에서만 작동한다.
47 // (Validate 함수가 없을 때 만든 검사라서 굳이 필요 없긴 하지만 일단 그대로 둠)
48 if (Selection.gameObjects.Length != 1)
49 {
50 EditorUtility.DisplayDialog("Anim pose Copy & Paste", "Please select one object", "OK");
51 return;
52 }
53
54 // 기억한 오브젝트가 아무것도 없으면 그냥 리턴
55 if (m_objs.Length <= 0)
56 {
57 return;
58 }
59
60 Transform[] selObjs = Selection.activeGameObject.GetComponentsInChildren<Transform>();
61
62 // 배열에 기억한 오브젝트드르이 수와 현재 선택된 오브젝트들의 수 중에 작은 수를 기준으로 작동한다.
63 int minLength = Mathf.Min(m_objs.Length, selObjs.Length);
64
65 Undo.RecordObjects(selObjs, "Anim Pose Paste");
66 for (int i = 0; i < minLength; i++)
67 {
68 selObjs[i].localPosition = m_positions[i];
69 selObjs[i].localRotation = m_rotations[i];
70 selObjs[i].localScale = m_scales[i];
71 }
72 }
73
74 [MenuItem("GameObject/SoxATK/AnimPose/Paste with Children", true)]
75 static bool ValidateAnimPosePaste()
76 {
77 return (Selection.gameObjects.Length == 1);
78 }
79}