我想检测PlayStation控制器的存在,以便正确显示按钮图标。每次检测到输入时,我都会调用以下方法:

public static void UpdateLastDevice(InputAction lastAction)
{
    if (lastAction != null && lastAction.activeControl != null)
        LastInputDevice = lastAction.activeControl.device; 
}

然后我有以下代码用于检查设备类型:

Debug.Log($"LastInputDevice: {LastInputDevice}");
if (LastInputDevice is DualShockGamepad)
    return ControllerType.PS4;
else if (LastInputDevice is XInputController)
    return ControllerType.Xbox;
else if (LastInputDevice is Keyboard)
    return ControllerType.Keyboard;
else
    return ControllerType.Unknown;

如果我通过Steam运行游戏,输入设备类型被报告为XInputControllerWindows。如果我在构建文件夹中放置一个steam_appid.txt文件,局部运行时,控制器确实注册为杜塞光盘控制器,但游戏仅在5秒内接收输入然后断开连接。

我没有改变任何Steam Input设置,包括所有方框都未选中,未设置默认控制器配置。控制器支持页面设置为“全尺寸控制器支持:Xbox控制器”。我只改变了它来包含PlayStation控制器看看这会带来什么变化 - 我不太清楚会不会有任何变化,并且到目前为止没有变化。

我看到其他Unity游戏成功展示了PS4/5图标,因此一定有一种方法可以让它正常工作!