Skip to content

Instantly share code, notes, and snippets.

@KzoNag
Created December 14, 2022 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KzoNag/9f5b243fbe3ba9a4a8f91e153909b914 to your computer and use it in GitHub Desktop.
Save KzoNag/9f5b243fbe3ba9a4a8f91e153909b914 to your computer and use it in GitHub Desktop.
UnityのInputSystenで接続されたデバイスの情報を確認する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using System.IO;
public class CheckDevice : MonoBehaviour
{
void Start()
{
foreach (var device in InputSystem.devices)
{
PrintDevice(device);
}
}
void OnEnable()
{
InputSystem.onDeviceChange += OnDeviceChange;
}
void OnDisable()
{
InputSystem.onDeviceChange -= OnDeviceChange;
}
private void OnDeviceChange(InputDevice device, InputDeviceChange deviceChange)
{
if (deviceChange != InputDeviceChange.Added)
{
return;
}
PrintDevice(device);
}
private void PrintDevice(InputDevice device)
{
if (device == null || device.description == null)
{
return;
}
Debug.Log($"### Device: {device.displayName}");
Debug.Log($"### Description: {device.description.ToJson()}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment