[Unity3D self-study record] The method of developing PicoVR to obtain the handle

There are two ways to get the handle, one is the XR method, and the other is the method in PicoSDK.
The first, the XR method

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;

public class PicoVRCS : MonoBehaviour
{
    List<InputDevice> foundControllers = new List<InputDevice>();
    // Start is called before the first frame update
    void Start()
    {
        InputDeviceCharacteristics leftTrackedControllerFilter = InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.TrackedDevice | InputDeviceCharacteristics.Left;   
        InputDevices.GetDevicesWithCharacteristics(leftTrackedControllerFilter, foundControllers);
    }

    void Update()
    {
        foundControllers[0].TryGetFeatureValue(CommonUsages.primaryButton, out bool isPress);
        if (isPress)
        {
            
        }
    }
}

The second is the method in PicoSDK

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
using UnityEngine.XR;

public class PicoVRControl : MonoBehaviour
{
    private static PicoVRControl ins;
    
    public static PicoVRControl Instance { get { return ins; } }


    public XRController LeftControl;
    public XRController RightControl;

    private bool isWait = false;
    // Start is called before the first frame update
    void Awake()
    {
        if (!ins) ins= this;

    }

    void Update()
    {
        Vector2 result;
        bool success = LeftControl.inputDevice.TryGetFeatureValue(CommonUsages.primary2DAxis, out result);
        bool success1 = RightControl.inputDevice.TryGetFeatureValue(CommonUsages.primary2DAxis, out result);
        if (success || success1)
        {
            Vector3 pos = CenterObj.position;
            float value = 2.5f;
            CenterObj.position = new Vector3(pos.x, pos.y + value * result.y, pos.z);
        }

        LeftControl.inputDevice.TryGetFeatureValue(CommonUsages.primaryButton, out bool isPressed);
        RightControl.inputDevice.TryGetFeatureValue(CommonUsages.primaryButton, out bool isPressed1);
        if ((isPressed || isPressed1) && !isWait)
        {

        }
    }
}

Guess you like

Origin blog.csdn.net/hackdjh/article/details/127584660