38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.XR.PXR;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.InputSystem.LowLevel;
|
|
|
|
public class PicoHandDeviceDoEvent : MonoBehaviour
|
|
{
|
|
public HandType handType;
|
|
CustomPicoHandDevice controller;
|
|
// Start is called before the first frame update
|
|
private void Start()
|
|
{
|
|
string hand_name = handType == HandType.HandLeft ? "LeftHand" : "RightHand";
|
|
controller = InputSystem.AddDevice<CustomPicoHandDevice>();
|
|
InputSystem.SetDeviceUsage(controller, hand_name);
|
|
}
|
|
|
|
public void GripOn()
|
|
{
|
|
using (StateEvent.From(controller,out var eventptr))
|
|
{
|
|
controller.grabActive.WriteValueFromObjectIntoEvent(eventptr, 1);
|
|
InputSystem.QueueEvent(eventptr);
|
|
}
|
|
}
|
|
|
|
public void GripOff()
|
|
{
|
|
using (StateEvent.From(controller, out var eventptr))
|
|
{
|
|
controller.grabActive.WriteValueFromObjectIntoEvent(eventptr, 0);
|
|
InputSystem.QueueEvent(eventptr);
|
|
}
|
|
}
|
|
}
|