获取手柄有两种方法,一种是XR的方法,一种是PicoSDK中的方法。
第一种,XR方法文章来源:https://www.toymoban.com/news/detail-581621.html
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)
{
}
}
}
第二种是PicoSDK中的方法文章来源地址https://www.toymoban.com/news/detail-581621.html
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)
{
}
}
}
到了这里,关于【Unity3D自学记录】开发PicoVR之获取手柄的方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!