HandRig.cs
2.9 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
using UnityEngine;
namespace UniHumanoid
{
public class HandRig : MonoBehaviour
{
[SerializeField]
Animator m_animator;
public Animator Animator
{
get { return m_animator; }
}
[SerializeField, Range(-1, 1)]
public float LeftStrech;
[SerializeField, Range(-1, 1)]
public float LeftSpread;
[SerializeField, Range(-1, 1)]
public float RightStrech;
[SerializeField, Range(-1, 1)]
public float RightSpread;
private void Reset()
{
m_animator = GetComponent<Animator>();
}
HumanPoseHandler m_handler;
public static HumanPoseHandler GetHandler(Animator animator)
{
if (animator == null)
{
return null;
}
if (animator.avatar == null)
{
return null;
}
if (!animator.avatar.isValid
|| !animator.avatar.isHuman)
{
return null;
}
return new HumanPoseHandler(animator.avatar, animator.transform);
}
HandPoseModifier m_updater;
private void Awake()
{
m_handler = GetHandler(m_animator);
if (m_handler == null)
{
enabled = false;
return;
}
m_updater = new HandPoseModifier();
}
HandPoseModifier.HandPose m_leftHand = new HandPoseModifier.HandPose();
HandPoseModifier.HandPose m_rightHand = new HandPoseModifier.HandPose();
HumanPose m_pose;
private void Update()
{
m_leftHand.ThumbStrech = LeftStrech;
m_leftHand.ThumbSpread = LeftSpread;
m_leftHand.IndexStrech = LeftStrech;
m_leftHand.IndexSpread = LeftSpread;
m_leftHand.MiddleStrech = LeftStrech;
m_leftHand.MiddleSpread = LeftSpread;
m_leftHand.RingStrech = LeftStrech;
m_leftHand.RingSpread = LeftSpread;
m_leftHand.LittleStrech = LeftStrech;
m_leftHand.LittleSpread = LeftSpread;
m_rightHand.ThumbStrech = RightStrech;
m_rightHand.ThumbSpread = RightSpread;
m_rightHand.IndexStrech = RightStrech;
m_rightHand.IndexSpread = RightSpread;
m_rightHand.MiddleStrech = RightStrech;
m_rightHand.MiddleSpread = RightSpread;
m_rightHand.RingStrech = RightStrech;
m_rightHand.RingSpread = RightSpread;
m_rightHand.LittleStrech = RightStrech;
m_rightHand.LittleSpread = RightSpread;
m_updater.LeftHandPose = m_leftHand;
m_updater.RightHandPose = m_rightHand;
m_handler.GetHumanPose(ref m_pose);
m_updater.Modify(ref m_pose);
m_handler.SetHumanPose(ref m_pose);
}
}
}