-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathSpringBonePivotInspector.cs
More file actions
executable file
·63 lines (52 loc) · 2.12 KB
/
SpringBonePivotInspector.cs
File metadata and controls
executable file
·63 lines (52 loc) · 2.12 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
53
54
55
56
57
58
59
60
61
62
63
using Unity.Animations.SpringBones.GameObjectExtensions;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace Unity.Animations.SpringBones
{
[CustomEditor(typeof(SpringBonePivot))]
[CanEditMultipleObjects]
public class SpringBonePivotInspector : Editor
{
bool isEngLang => !EditorPrefs.GetBool("UCSB_JLM");
public override void OnInspectorGUI()
{
InitializeData();
if (GUILayout.Button(isEngLang ? "Select bone" : "ボーンを選択", SpringBoneGUIStyles.ButtonStyle))
{
Selection.objects = bones.Select(bone => bone.gameObject).ToArray();
}
base.OnInspectorGUI();
var managerCount = managers.Length;
for (int managerIndex = 0; managerIndex < managerCount; managerIndex++)
{
EditorGUILayout.ObjectField("Manager", managers[managerIndex], typeof(SpringManager), true);
}
var boneCount = bones.Length;
for (int boneIndex = 0; boneIndex < boneCount; boneIndex++)
{
EditorGUILayout.ObjectField("Bone", bones[boneIndex], typeof(SpringBone), true);
}
}
private SpringManager[] managers;
private SpringBone[] bones;
private void InitializeData()
{
if (managers != null && managers.Length > 0) { return; }
managers = targets
.Select(target => target as Component)
.Where(target => target != null)
.Select(target => target.GetComponentInParent<SpringManager>())
.Where(manager => manager != null)
.Distinct()
.ToArray();
var pivots = targets
.Where(target => target is Component)
.Select(target => ((Component)target).transform)
.ToArray();
bones = GameObjectUtil.FindComponentsOfType<SpringBone>()
.Where(bone => pivots.Contains(bone.pivotNode))
.ToArray();
}
}
}