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.

99 lines
3.0 KiB

using System;
using UnityEngine;
namespace UDE_HAND_INTERACTION
{
public class HandStaticPose : MonoBehaviour
{
private StaticPoseDetector staticPoseDetector => GetComponentInParent<StaticPoseDetector>();
public HandPose _handPose;
[HideInInspector]
public HandPose HandPose
{
get
{
if (_handPose == null)
{
_handPose = new();
if(name.Contains("left") || name.Contains("Left"))
{
_handPose.Handedness = Handedness.Left;
}
else
{
_handPose.Handedness = Handedness.Right;
}
}
return _handPose;
}
}
public enum Handness
{
Left,
Right
}
public Handness handness => (Handness)_handPose.Handedness;
[HideInInspector]
public HandPerfabResource _HPResource;
[HideInInspector]
public GameObject _virtualHand;
[Space(5)]
public bool ConsiderWrist = false;
private bool InDetected = false;
public class StaticPoseDetectEventArgs : EventArgs
{
public HandStaticPose _Pose { get; private set; }
public bool IsDetected { get; private set; }
public StaticPoseDetectEventArgs(HandStaticPose pose, bool isDetected)
{
_Pose = pose;
IsDetected = isDetected;
}
}
public delegate void StaticPoseDetectResultEventHandler(object sender, StaticPoseDetectEventArgs e);
public event StaticPoseDetectResultEventHandler OnPoseDetectResult;
public void CreateVisualModel()
{
void Create()
{
var virtualHand = Instantiate(_HPResource.GetHand(HandPose.Handedness), transform);
_virtualHand = virtualHand.gameObject;
_virtualHand.name = "Visual" + transform.name;
_virtualHand.GetComponentInChildren<SkinnedMeshRenderer>().material = staticPoseDetector.DefaultGrid;
Pose pose = PoseManager.GlobalPoseScaled(transform, transform.GetPose(Space.Self));
virtualHand.SetPose(HandPose, pose);
DestroyImmediate(virtualHand);
DestroyImmediate(_virtualHand.GetComponent<DollHand>());
_virtualHand.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
}
if(_virtualHand != null)
{
DestroyImmediate(_virtualHand);
}
Create();
}
public void IsPoseDetected(bool result)
{
if (result != InDetected)
{
InDetected = result;
OnPoseDetectResult(this, new StaticPoseDetectEventArgs(this, result));
}
}
}
}