Created
December 14, 2022 06:42
-
-
Save KzoNag/9f5b243fbe3ba9a4a8f91e153909b914 to your computer and use it in GitHub Desktop.
UnityのInputSystenで接続されたデバイスの情報を確認する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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