MuscleDebug.cs
2.47 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Linq;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UniHumanoid
{
public class MuscleDebug : MonoBehaviour
{
Avatar GetAvatar()
{
var animator = GetComponent<Animator>();
if (animator != null && animator.avatar != null)
{
return animator.avatar;
}
var transfer = GetComponent<HumanPoseTransfer>();
if (transfer != null && transfer.Avatar != null)
{
return transfer.Avatar;
}
return null;
}
HumanPoseHandler m_handler;
public HumanPose m_pose;
[Serializable]
public struct Muscle
{
public int Index;
public string Name;
public float Value;
}
public Vector3 BodyPosition;
public Muscle[] Muscles;
private void OnEnable()
{
var avatar = GetAvatar();
if (avatar == null)
{
enabled = false;
return;
}
m_handler = new HumanPoseHandler(avatar, transform);
Muscles = HumanTrait.MuscleName.Select((x, i) =>
{
return new Muscle
{
Index = i,
Name = x,
};
})
.ToArray()
;
}
private void OnDisable()
{
}
private void Update()
{
m_handler.GetHumanPose(ref m_pose);
BodyPosition = m_pose.bodyPosition;
for (int i = 0; i < m_pose.muscles.Length; ++i)
{
Muscles[i].Value = m_pose.muscles[i];
}
}
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(MuscleDebug.Muscle))]
public class MuscleDrawer : PropertyDrawer
{
public override void OnGUI(Rect position,
SerializedProperty property, GUIContent label)
{
var nameProp = property.FindPropertyRelative("Name");
var valueProp = property.FindPropertyRelative("Value");
/*
var labl = string.Format("{0}: {1}",
nameProp.stringValue,
valueProp.floatValue
);
*/
EditorGUI.LabelField(position, nameProp.stringValue, string.Format("{0:0.00}", valueProp.floatValue));
}
}
#endif
}