using UnityEngine; namespace UDE_HAND_INTERACTION { public class HandInteraction : MonoBehaviour { [SerializeField] [Tooltip("Transform used as a reference to measure the local data of the HandGrabPose")] public Transform _relativeTo; public Transform RelativeTo => _relativeTo; public HandPose _handPose = new(); [HideInInspector] public HandPose HandPose => _handPose; public enum Handness { Left, Right } public Handness handness => (Handness)_handPose.Handedness; public HandPerfabResource _HPResource; private Vector3 TipPos; public Pose RelativePose { get { if (_relativeTo != null) { return PoseManager.DeltaScaled(_relativeTo, transform); } else { return transform.GetPose(Space.Self); } } } [HideInInspector] public bool UseInteract { get; private set; } void Awake() { if(transform.Find("PivotPoint") == null) { var virtualHand = Instantiate(_HPResource.GetHand(HandPose.Handedness), transform); Pose pose = PoseManager.GlobalPoseScaled(RelativeTo, RelativePose); virtualHand.SetPose(HandPose, pose); TipPos = virtualHand.TipPos.position; DestroyImmediate(virtualHand.gameObject); var Pivot = new GameObject("PivotPoint"); Pivot.transform.parent = transform; Pivot.transform.position = TipPos; } } public void SetUseInteract() { UseInteract = true; } } }