Files
PrinceOfGlory/Assets/Scripts/MyHandReset/PXR_PicoHandPinchGesture.cs
kridoo 6e91a0c7f0 111
2025-09-15 17:32:08 +08:00

58 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using Unity.XR.PXR;
using UnityEngine;
public class PXR_PicoHandPinchGesture : PicoHandDeviceDoEvent
{
private bool aimRayTouched = false;
public bool AimRayTouched { get => aimRayTouched; set => aimRayTouched = value; }
private bool pinch = false;
private HandAimState aimState = new HandAimState();
public float PinchStrength { get; private set; }
public bool Pinch
{
get => pinch;
set {
if (pinch != value)
{
if (value)
{
GripOn();
}
else
{
GripOff();
}
}
pinch = value;
}
}
// Update is called once per frame
void Update()
{
UpdateAimState();
}
private void UpdateAimState()
{
if (PXR_HandTracking.GetAimState(handType, ref aimState))
{
PinchStrength = aimState.touchStrengthRay;
AimRayTouched = (aimState.aimStatus & HandAimStatus.AimRayTouched) != 0;
if (PinchStrength > 0.6f || AimRayTouched)
{
Pinch = true;
}
else
{
Pinch = false;
}
}
}
}