AlicizaX/Client/Assets/Scripts/Hotfix/GameLogic/TestUIMono.cs
2025-11-17 20:29:03 +08:00

34 lines
873 B
C#

using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
public class NewInputSystemControllerEvents : MonoBehaviour
{
private void OnEnable()
{
InputSystem.onDeviceChange += OnDeviceChanged;
}
private void OnDisable()
{
InputSystem.onDeviceChange -= OnDeviceChanged;
}
private void OnDeviceChanged(InputDevice device, InputDeviceChange change)
{
// 只关心游戏手柄
if (device is Gamepad)
{
switch (change)
{
case InputDeviceChange.Added:
Debug.Log($"手柄已连接: {device.displayName}");
break;
case InputDeviceChange.Removed:
Debug.Log($"手柄已断开: {device.displayName}");
break;
}
}
}
}