Unity VR не может найти билиотеку XR
Решил сделать игру в Unity на версии 2022.3.62f1. Подключил все XR библиотеки и приступил к коду, но вылезла ошибка CS0117"InputDevice" не содержит определение для "GetDevices".
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
public class HandController : MonoBehaviour
{
void Start()
{
List<InputDevice> devices = new List<InputDevice>();
InputDevice.GetDevices(devices);
foreach (InputDevice device in devices)
{
Debug.Log($"Device Name: {device.name}");
Debug.Log($"Characteristics: {device.characteristics}");
}
}
void Update() { }
}
Ответы (1 шт):
Автор решения: FrozenM
→ Ссылка
Вроде с какой-то версии InputDevice.GetDevices() устаревший и с какой-то версии он удален. Что-то вроде этого попытайся.
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
public class HandController : MonoBehaviour
{
private List<InputDevice> devices = new List<InputDevice>();
private void Start()
{
// Подписываемся на события подключения/отключения устройств
InputDevices.deviceConnected += OnDeviceConnected;
InputDevices.deviceDisconnected += OnDeviceDisconnected;
// Получаем уже подключённые устройства
InputDevices.GetDevices(devices);
LogDevices("Уже подключённые устройства:");
}
private void OnDeviceConnected(InputDevice device)
{
Debug.Log($"Устройство подключено: {device.name}");
if (!devices.Contains(device)) devices.Add(device);
}
private void OnDeviceDisconnected(InputDevice device)
{
Debug.Log($"Устройство отключено: {device.name}");
devices.Remove(device);
}
private void LogDevices(string message)
{
Debug.Log(message);
foreach (InputDevice device in devices)
{
Debug.Log($"- {device.name} | Тип: {device.characteristics}");
}
}
private void OnDestroy()
{
// Отписываемся от событий при уничтожении объекта
InputDevices.deviceConnected -= OnDeviceConnected;
InputDevices.deviceDisconnected -= OnDeviceDisconnected;
}
}