58 lines
1.3 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|
|
}
|