-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathSpringManagerInspector.cs
More file actions
executable file
·81 lines (68 loc) · 2.79 KB
/
SpringManagerInspector.cs
File metadata and controls
executable file
·81 lines (68 loc) · 2.79 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace Unity.Animations.SpringBones
{
using SpringManagerButton = SpringManagerInspector.InspectorButton<SpringManager>;
[CustomEditor(typeof(SpringManager))]
[CanEditMultipleObjects]
public class SpringManagerInspector : Editor
{
bool isEngLang => !EditorPrefs.GetBool("UCSB_JLM");
public class InspectorButton<T>
{
public InspectorButton(string label, System.Action<T> onPress)
{
Label = label;
OnPress = onPress;
}
public string Label { get; set; }
public System.Action<T> OnPress { get; set; }
public void Show(T target)
{
if (GUILayout.Button(Label)) { OnPress(target); }
}
}
public override void OnInspectorGUI()
{
if (targets.Length == 1)
{
// Only show buttons if one component is selected
if (actionButtons == null || actionButtons.Length == 0)
{
actionButtons = new[] {
new SpringManagerButton(isEngLang ? "Display Spring Window" : "窓を表示", ShowSpringWindow),
new SpringManagerButton(isEngLang ? "Select All SpringBone" : "SpringBoneを全て選択", SelectAllBones),
new SpringManagerButton(isEngLang ? "Update SpringBone List" : "SpringBoneリストを更新", UpdateBoneList)
};
}
EditorGUILayout.Space();
var manager = (SpringManager)target;
for (int buttonIndex = 0; buttonIndex < actionButtons.Length; buttonIndex++)
{
actionButtons[buttonIndex].Show(manager);
}
EditorGUILayout.Space();
var boneCount = (manager.springBones != null) ? manager.springBones.Length : 0;
GUILayout.Label("Bones: " + boneCount);
EditorGUILayout.Space();
}
base.OnInspectorGUI();
}
// private
private SpringManagerButton[] actionButtons;
private static void ShowSpringWindow(SpringManager manager)
{
SpringBoneWindow.ShowWindow();
}
private static void SelectAllBones(SpringManager manager)
{
var bones = manager.GetComponentsInChildren<SpringBone>(true);
Selection.objects = bones.Select(item => item.gameObject).ToArray();
}
private static void UpdateBoneList(SpringManager manager)
{
SpringBoneSetup.FindAndAssignSpringBones(manager, true);
}
}
}