Unity Udexreal开发插件包
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.0 KiB

using UnityEngine;
namespace UDE_HAND_INTERACTION
{
[RequireComponent(typeof(DollHand))]
public class VirtualHand : MonoBehaviour
{
[SerializeField]
private DollHand Doll;
[SerializeField]
//[UnityEngine.Serialization.FormerlySerializedAs("_handGrabPoint")]
private HandGrabPose _handGrabPose;
public Transform TipPos;
protected virtual void Reset()
{
Doll = this.GetComponent<DollHand>();
_handGrabPose = this.GetComponentInParent<HandGrabPose>();
}
protected virtual void OnValidate()
{
if (Doll == null)
{
return;
}
if (_handGrabPose == null)
{
HandGrabPose point = this.GetComponentInParent<HandGrabPose>();
if (point != null)
{
SetPose(point);
}
}
else if (_handGrabPose != null)
{
SetPose(_handGrabPose);
}
}
protected virtual void Start()
{
this.AssertField(Doll, nameof(Doll));
}
public void SetPose(HandGrabPose handGrabPose)
{
HandPose userPose = handGrabPose.HandPose;
if (userPose == null)
{
return;
}
Doll.SetJointRotations(userPose.JointRotations);
SetRootPose(handGrabPose.RelativePose, handGrabPose.RelativeTo);
}
public void SetPose(HandPose userPose, Pose rootPose)
{
Doll.SetJointRotations(userPose.JointRotations);
Doll.SetRootPose(rootPose);
}
public void SetRootPose(Pose rootPose, Transform relativeTo)
{
Pose pose = rootPose;
if (relativeTo != null)
{
pose = PoseManager.GlobalPoseScaled(relativeTo, rootPose);
}
Doll.SetRootPose(pose);
}
}
}