新增PC/MacOS 对于SwitchPro手柄的支持

This commit is contained in:
sin365 2025-09-26 13:40:40 +08:00
parent 3c844befe1
commit 5f3412109e
10 changed files with 195 additions and 24 deletions

View File

@ -423,32 +423,32 @@ public static class MameSingleControllSetter
break; break;
//后续修改后 支持P3 P4 //后续修改后 支持P3 P4
case 2: case 2:
singlecontrol.tg_INSERT_COIN = MotionKey.FinalKey; singlecontrol.tg_INSERT_COIN = MotionKey.P3_INSERT_COIN;
singlecontrol.tg_GAMESTART = MotionKey.FinalKey; singlecontrol.tg_GAMESTART = MotionKey.P3_GAMESTART;
singlecontrol.tg_UP = MotionKey.FinalKey; singlecontrol.tg_UP = MotionKey.P3_UP;
singlecontrol.tg_DOWN = MotionKey.FinalKey; singlecontrol.tg_DOWN = MotionKey.P3_DOWN;
singlecontrol.tg_LEFT = MotionKey.FinalKey; singlecontrol.tg_LEFT = MotionKey.P3_LEFT;
singlecontrol.tg_RIGHT = MotionKey.FinalKey; singlecontrol.tg_RIGHT = MotionKey.P3_RIGHT;
singlecontrol.tg_BTN_A = MotionKey.FinalKey; singlecontrol.tg_BTN_A = MotionKey.P3_BTN_1;
singlecontrol.tg_BTN_B = MotionKey.FinalKey; singlecontrol.tg_BTN_B = MotionKey.P3_BTN_2;
singlecontrol.tg_BTN_C = MotionKey.FinalKey; singlecontrol.tg_BTN_C = MotionKey.P3_BTN_3;
singlecontrol.tg_BTN_D = MotionKey.FinalKey; singlecontrol.tg_BTN_D = MotionKey.P3_BTN_4;
singlecontrol.tg_BTN_E = MotionKey.FinalKey; singlecontrol.tg_BTN_E = MotionKey.P3_BTN_5;
singlecontrol.tg_BTN_F = MotionKey.FinalKey; singlecontrol.tg_BTN_F = MotionKey.P3_BTN_6;
break; break;
case 3: case 3:
singlecontrol.tg_INSERT_COIN = MotionKey.FinalKey; singlecontrol.tg_INSERT_COIN = MotionKey.P4_INSERT_COIN;
singlecontrol.tg_GAMESTART = MotionKey.FinalKey; singlecontrol.tg_GAMESTART = MotionKey.P4_GAMESTART;
singlecontrol.tg_UP = MotionKey.FinalKey; singlecontrol.tg_UP = MotionKey.P4_UP;
singlecontrol.tg_DOWN = MotionKey.FinalKey; singlecontrol.tg_DOWN = MotionKey.P4_DOWN;
singlecontrol.tg_LEFT = MotionKey.FinalKey; singlecontrol.tg_LEFT = MotionKey.P4_LEFT;
singlecontrol.tg_RIGHT = MotionKey.FinalKey; singlecontrol.tg_RIGHT = MotionKey.P4_RIGHT;
singlecontrol.tg_BTN_A = MotionKey.FinalKey; singlecontrol.tg_BTN_A = MotionKey.P4_BTN_1;
singlecontrol.tg_BTN_B = MotionKey.FinalKey; singlecontrol.tg_BTN_B = MotionKey.P4_BTN_2;
singlecontrol.tg_BTN_C = MotionKey.FinalKey; singlecontrol.tg_BTN_C = MotionKey.P4_BTN_3;
singlecontrol.tg_BTN_D = MotionKey.FinalKey; singlecontrol.tg_BTN_D = MotionKey.P4_BTN_4;
singlecontrol.tg_BTN_E = MotionKey.FinalKey; singlecontrol.tg_BTN_E = MotionKey.P4_BTN_5;
singlecontrol.tg_BTN_F = MotionKey.FinalKey; singlecontrol.tg_BTN_F = MotionKey.P4_BTN_6;
break; break;
} }
} }

View File

@ -148,6 +148,25 @@ namespace AxibugEmuOnline.Client.Settings
controller.SetBinding(EssgeeSingleKey.RIGHT, device.JOYSTICK.Right, 1); controller.SetBinding(EssgeeSingleKey.RIGHT, device.JOYSTICK.Right, 1);
} }
public override void Bind(StandaloneSwitchProController_D device, ControllerBinder controller)
{
controller.SetBinding(EssgeeSingleKey.OPTION_1, device.Plus, 0);
controller.SetBinding(EssgeeSingleKey.OPTION_2, device.Minus, 0);
controller.SetBinding(EssgeeSingleKey.UP, device.Up, 0);
controller.SetBinding(EssgeeSingleKey.DOWN, device.Down, 0);
controller.SetBinding(EssgeeSingleKey.LEFT, device.Left, 0);
controller.SetBinding(EssgeeSingleKey.RIGHT, device.Right, 0);
controller.SetBinding(EssgeeSingleKey.BTN_1, device.A, 0);
controller.SetBinding(EssgeeSingleKey.BTN_2, device.B, 0);
controller.SetBinding(EssgeeSingleKey.BTN_3, device.X, 0);
controller.SetBinding(EssgeeSingleKey.BTN_4, device.Y, 0);
controller.SetBinding(EssgeeSingleKey.UP, device.LeftStick.Up, 1);
controller.SetBinding(EssgeeSingleKey.DOWN, device.LeftStick.Down, 1);
controller.SetBinding(EssgeeSingleKey.LEFT, device.LeftStick.Left, 1);
controller.SetBinding(EssgeeSingleKey.RIGHT, device.LeftStick.Right, 1);
}
public override void Bind(SwitchJoyCon_D device, ControllerBinder controller) public override void Bind(SwitchJoyCon_D device, ControllerBinder controller)
{ {
controller.SetBinding(EssgeeSingleKey.OPTION_1, device.Plus, 0); controller.SetBinding(EssgeeSingleKey.OPTION_1, device.Plus, 0);

View File

@ -159,6 +159,26 @@ namespace AxibugEmuOnline.Client.Settings
controller.SetBinding(UMAMEKSingleKey.RIGHT, device.JOYSTICK.Right, 1); controller.SetBinding(UMAMEKSingleKey.RIGHT, device.JOYSTICK.Right, 1);
} }
public override void Bind(StandaloneSwitchProController_D device, ControllerBinder controller)
{
controller.SetBinding(UMAMEKSingleKey.INSERT_COIN, device.Minus, 0);
controller.SetBinding(UMAMEKSingleKey.GAMESTART, device.Plus, 0);
controller.SetBinding(UMAMEKSingleKey.UP, device.Up, 0);
controller.SetBinding(UMAMEKSingleKey.DOWN, device.Down, 0);
controller.SetBinding(UMAMEKSingleKey.LEFT, device.Left, 0);
controller.SetBinding(UMAMEKSingleKey.RIGHT, device.Right, 0);
controller.SetBinding(UMAMEKSingleKey.BTN_A, device.B, 0);
controller.SetBinding(UMAMEKSingleKey.BTN_B, device.A, 0);
controller.SetBinding(UMAMEKSingleKey.BTN_C, device.X, 0);
controller.SetBinding(UMAMEKSingleKey.BTN_D, device.Y, 0);
controller.SetBinding(UMAMEKSingleKey.BTN_E, device.LeftSL, 0);
controller.SetBinding(UMAMEKSingleKey.BTN_F, device.RightSL, 0);
controller.SetBinding(UMAMEKSingleKey.UP, device.LeftStick.Up, 1);
controller.SetBinding(UMAMEKSingleKey.DOWN, device.LeftStick.Down, 1);
controller.SetBinding(UMAMEKSingleKey.LEFT, device.LeftStick.Left, 1);
controller.SetBinding(UMAMEKSingleKey.RIGHT, device.LeftStick.Right, 1);
}
public override void Bind(SwitchJoyCon_D device, ControllerBinder controller) public override void Bind(SwitchJoyCon_D device, ControllerBinder controller)
{ {
controller.SetBinding(UMAMEKSingleKey.INSERT_COIN, device.Minus, 0); controller.SetBinding(UMAMEKSingleKey.INSERT_COIN, device.Minus, 0);

View File

@ -18,6 +18,7 @@ public abstract class EmuCoreBinder<T> : InternalEmuCoreBinder,
IDeviceBinder<T, XboxController_D>, IDeviceBinder<T, XboxController_D>,
IDeviceBinder<T, PSVController_D>, IDeviceBinder<T, PSVController_D>,
IDeviceBinder<T, ScreenGamepad_D>, IDeviceBinder<T, ScreenGamepad_D>,
IDeviceBinder<T, StandaloneSwitchProController_D>,
IDeviceBinder<T, SwitchJoyCon_D> IDeviceBinder<T, SwitchJoyCon_D>
where T : Enum where T : Enum
{ {
@ -101,6 +102,7 @@ public abstract class EmuCoreBinder<T> : InternalEmuCoreBinder,
else if (device is XboxController_D xbC) Bind(xbC, binding); else if (device is XboxController_D xbC) Bind(xbC, binding);
else if (device is PSVController_D psvC) Bind(psvC, binding); else if (device is PSVController_D psvC) Bind(psvC, binding);
else if (device is ScreenGamepad_D screenGamepad) Bind(screenGamepad, binding); else if (device is ScreenGamepad_D screenGamepad) Bind(screenGamepad, binding);
else if (device is StandaloneSwitchProController_D standaloneswitchproC) Bind(standaloneswitchproC, binding);
else if (device is SwitchJoyCon_D nsJoyCon) Bind(nsJoyCon, binding); else if (device is SwitchJoyCon_D nsJoyCon) Bind(nsJoyCon, binding);
else throw new NotImplementedException($"{device.GetType()}"); else throw new NotImplementedException($"{device.GetType()}");
} }
@ -324,5 +326,6 @@ public abstract class EmuCoreBinder<T> : InternalEmuCoreBinder,
public abstract void Bind(XboxController_D device, ControllerBinder controller); public abstract void Bind(XboxController_D device, ControllerBinder controller);
public abstract void Bind(PSVController_D device, ControllerBinder controller); public abstract void Bind(PSVController_D device, ControllerBinder controller);
public abstract void Bind(ScreenGamepad_D device, ControllerBinder controller); public abstract void Bind(ScreenGamepad_D device, ControllerBinder controller);
public abstract void Bind(StandaloneSwitchProController_D device, ControllerBinder controller);
public abstract void Bind(SwitchJoyCon_D device, ControllerBinder controller); public abstract void Bind(SwitchJoyCon_D device, ControllerBinder controller);
} }

View File

@ -121,6 +121,25 @@ namespace AxibugEmuOnline.Client.Settings
controller.SetBinding(EnumButtonType.UP, device.JOYSTICK.Up, 1); controller.SetBinding(EnumButtonType.UP, device.JOYSTICK.Up, 1);
controller.SetBinding(EnumButtonType.DOWN, device.JOYSTICK.Down, 1); controller.SetBinding(EnumButtonType.DOWN, device.JOYSTICK.Down, 1);
} }
public override void Bind(StandaloneSwitchProController_D device, ControllerBinder controller)
{
controller.SetBinding(EnumButtonType.LEFT, device.Left, 0);
controller.SetBinding(EnumButtonType.RIGHT, device.Right, 0);
controller.SetBinding(EnumButtonType.UP, device.Up, 0);
controller.SetBinding(EnumButtonType.DOWN, device.Down, 0);
controller.SetBinding(EnumButtonType.A, device.A, 0);
controller.SetBinding(EnumButtonType.B, device.B, 0);
controller.SetBinding(EnumButtonType.SELECT, device.Minus, 0);
controller.SetBinding(EnumButtonType.START, device.Plus, 0);
controller.SetBinding(EnumButtonType.MIC, device.RightSL, 0);
controller.SetBinding(EnumButtonType.LEFT, device.LeftStick.Left, 1);
controller.SetBinding(EnumButtonType.RIGHT, device.LeftStick.Right, 1);
controller.SetBinding(EnumButtonType.UP, device.LeftStick.Up, 1);
controller.SetBinding(EnumButtonType.DOWN, device.LeftStick.Down, 1);
}
public override void Bind(SwitchJoyCon_D device, ControllerBinder controller) public override void Bind(SwitchJoyCon_D device, ControllerBinder controller)
{ {
controller.SetBinding(EnumButtonType.LEFT, device.Left, 0); controller.SetBinding(EnumButtonType.LEFT, device.Left, 0);

View File

@ -125,6 +125,21 @@ namespace AxibugEmuOnline.Client.Settings
controller.SetBinding(StoicGooseKey.A, device.BTN_B, 0); controller.SetBinding(StoicGooseKey.A, device.BTN_B, 0);
} }
public override void Bind(StandaloneSwitchProController_D device, ControllerBinder controller)
{
controller.SetBinding(StoicGooseKey.Start, device.Plus, 0);
controller.SetBinding(StoicGooseKey.X1, device.Up, 0);
controller.SetBinding(StoicGooseKey.X2, device.Down, 0);
controller.SetBinding(StoicGooseKey.X3, device.Left, 0);
controller.SetBinding(StoicGooseKey.X4, device.Right, 0);
controller.SetBinding(StoicGooseKey.Y1, device.RightStick.Up, 0);
controller.SetBinding(StoicGooseKey.Y2, device.RightStick.Down, 0);
controller.SetBinding(StoicGooseKey.Y3, device.RightStick.Left, 0);
controller.SetBinding(StoicGooseKey.Y4, device.RightStick.Right, 0);
controller.SetBinding(StoicGooseKey.B, device.A, 0);
controller.SetBinding(StoicGooseKey.A, device.B, 0);
}
public override void Bind(SwitchJoyCon_D device, ControllerBinder controller) public override void Bind(SwitchJoyCon_D device, ControllerBinder controller)
{ {
controller.SetBinding(StoicGooseKey.Start, device.Plus, 0); controller.SetBinding(StoicGooseKey.Start, device.Plus, 0);

View File

@ -158,6 +158,29 @@ namespace AxibugEmuOnline.Client
break; break;
} }
} }
public override void Bind(StandaloneSwitchProController_D device, ControllerBinder controller)
{
switch (controller.ControllerIndex)
{
case 0://设置标准UI控制
controller.SetBinding(EnumCommand.Back, device.B, 0);
controller.SetBinding(EnumCommand.Enter, device.A, 0);
controller.SetBinding(EnumCommand.OptionMenu, device.Plus, 0);
controller.SetBinding(EnumCommand.SelectItemDown, device.Down, 0);
controller.SetBinding(EnumCommand.SelectItemLeft, device.Left, 0);
controller.SetBinding(EnumCommand.SelectItemRight, device.Right, 0);
controller.SetBinding(EnumCommand.SelectItemUp, device.Up, 0);
controller.SetBinding(EnumCommand.SelectItemDown, device.LeftStick.Down, 1);
controller.SetBinding(EnumCommand.SelectItemLeft, device.LeftStick.Left, 1);
controller.SetBinding(EnumCommand.SelectItemRight, device.LeftStick.Right, 1);
controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1);
break;
case 1://游戏中UI控制
controller.SetBinding(EnumCommand.OptionMenu, device.RightStickPress, 0);
break;
}
}
public override void Bind(SwitchJoyCon_D device, ControllerBinder controller) public override void Bind(SwitchJoyCon_D device, ControllerBinder controller)
{ {
switch (controller.ControllerIndex) switch (controller.ControllerIndex)

View File

@ -0,0 +1,34 @@
using AxibugProtobuf;
namespace AxibugEmuOnline.Client.InputDevices
{
public class StandaloneSwitchProController_D : InputDevice_D
{
public Button_C LeftSL;
public Button_C LeftSR;
public Button_C RightSL;
public Button_C RightSR;
public Button_C B;
public Button_C A;
public Button_C Y;
public Button_C X;
public Button_C Up;
public Button_C Down;
public Button_C Left;
public Button_C Right;
public Button_C Minus;
public Button_C Plus;
public Stick_C LeftStick;
public Stick_C RightStick;
public Button_C LeftStickPress;
public Button_C RightStickPress;
public StandaloneSwitchProController_D(InputResolver resolver) : base(resolver) { }
public override GamePadType PadType => GamePadType.SwitchProControl;
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 77370bc30da5106418f2ec162759b122

View File

@ -77,6 +77,15 @@ On-Screen Keyboard这个是真正的屏幕软键盘。
else newDevice = new DualShockController_D(this); else newDevice = new DualShockController_D(this);
} }
#endif #endif
#if UNITY_STANDALONE
//PC Mac 平台的SwitchPro 手柄其他平台无法编译包括NS电脑连NSPro手柄是不一样的
//inputsystem 文档说的是SwitchProControllerHIDA Nintendo Switch Pro controller connected to a desktop mac/windows PC using the HID interface.
else if (ipdev is UnityEngine.InputSystem.Switch.SwitchProControllerHID)
{
newDevice = new StandaloneSwitchProController_D(this);
}
#endif
else if (ipdev is XInputController) else if (ipdev is XInputController)
{ {
newDevice = new XboxController_D(this); newDevice = new XboxController_D(this);
@ -309,6 +318,33 @@ On-Screen Keyboard这个是真正的屏幕软键盘。
mapper[ds_d.RightStick] = ipDsGamePad.rightStick; mapper[ds_d.RightStick] = ipDsGamePad.rightStick;
} }
#endif #endif
#if UNITY_STANDALONE
//PC Mac 平台的SwitchPro 手柄其他平台无法编译包括NS电脑连NSPro手柄是不一样的
//inputsystem 文档说的是SwitchProControllerHIDA Nintendo Switch Pro controller connected to a desktop mac/windows PC using the HID interface.
else if (device_d is StandaloneSwitchProController_D standaloneswitchpro_d)
{
var ipdevice_joycon = ipdevice as UnityEngine.InputSystem.Switch.SwitchProControllerHID;
mapper[standaloneswitchpro_d.LeftSL] = ipdevice_joycon.leftTrigger;
mapper[standaloneswitchpro_d.LeftSR] = ipdevice_joycon.leftShoulder;
mapper[standaloneswitchpro_d.RightSL] = ipdevice_joycon.rightTrigger;
mapper[standaloneswitchpro_d.RightSR] = ipdevice_joycon.rightShoulder;
mapper[standaloneswitchpro_d.B] = ipdevice_joycon.bButton;
mapper[standaloneswitchpro_d.A] = ipdevice_joycon.aButton;
mapper[standaloneswitchpro_d.Y] = ipdevice_joycon.yButton;
mapper[standaloneswitchpro_d.X] = ipdevice_joycon.xButton;
mapper[standaloneswitchpro_d.Up] = ipdevice_joycon.dpad.up;
mapper[standaloneswitchpro_d.Down] = ipdevice_joycon.dpad.down;
mapper[standaloneswitchpro_d.Left] = ipdevice_joycon.dpad.left;
mapper[standaloneswitchpro_d.Right] = ipdevice_joycon.dpad.right;
mapper[standaloneswitchpro_d.Minus] = ipdevice_joycon.selectButton;
mapper[standaloneswitchpro_d.Plus] = ipdevice_joycon.startButton;
mapper[standaloneswitchpro_d.LeftStick] = ipdevice_joycon.leftStick;
mapper[standaloneswitchpro_d.RightStick] = ipdevice_joycon.rightStick;
mapper[standaloneswitchpro_d.RightStickPress] = ipdevice_joycon.rightStickButton;
mapper[standaloneswitchpro_d.LeftStickPress] = ipdevice_joycon.leftStickButton;
}
#endif
else if (device_d is XboxController_D xbox_d) else if (device_d is XboxController_D xbox_d)
{ {
var ipXInputGamePad = ipdevice as XInputController; var ipXInputGamePad = ipdevice as XInputController;