Unity/유니티VR
Oculus Quest 컨트롤러 + input 받아오기
도이(doi)
2020. 9. 6. 11:35
728x90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
public class handPresence : MonoBehaviour
{
public InputDeviceCharacteristics controllerCharacteristics;
public List<GameObject> controllerPrefabs;
private InputDevice targetDevice;
private GameObject spawnedController;
void Start()
{
List<InputDevice> devices = new List<InputDevice>();
InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices);
//input devices 체크 debug
foreach(var item in devices)
{
Debug.Log(item.name + item.characteristics);
}
if(devices.Count > 0)
{
targetDevice = devices[0];
//targetDevice의 이름과 동일한 controller를 찾는다.
GameObject prefab = controllerPrefabs.Find(controller => controller.name == targetDevice.name);
if(prefab) //prefab이 존재할 때
{
spawnedController = Instantiate(prefab, transform);
Debug.Log(prefab);
}
else //prefab이 controller를 찾지 못할 때
{
Debug.LogError("Did not find corresponding controller model.");
spawnedController = Instantiate(controllerPrefabs[0], transform);
}
}
}
void Update()
{
//input값 debug
if (targetDevice.TryGetFeatureValue(CommonUsages.primaryButton, out bool primaryButtonValue) &&
primaryButtonValue)
Debug.Log("Pressing Primary Button");
if (targetDevice.TryGetFeatureValue(CommonUsages.trigger, out float triggerValue) &&
triggerValue > 0.1f)
Debug.Log("Triggerr pressed" + triggerValue);
if (targetDevice.TryGetFeatureValue(CommonUsages.primary2DAxis, out Vector2 primary2DAxisValue) &&
primary2DAxisValue != Vector2.zero)
Debug.Log("Primary TouchPad" + primary2DAxisValue);
}
}
728x90
반응형