AlicizaX/Client/Assets/Scripts/Hotfix/GameLogic/TestUIMono.cs

34 lines
873 B
C#
Raw Normal View History

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