diff --git a/AxibugEmuOnline.Client/Assets/Plugins/AxiNSApi/AxiNSIO.cs b/AxibugEmuOnline.Client/Assets/Plugins/AxiNSApi/AxiNSIO.cs index a9211848..318995c8 100644 --- a/AxibugEmuOnline.Client/Assets/Plugins/AxiNSApi/AxiNSIO.cs +++ b/AxibugEmuOnline.Client/Assets/Plugins/AxiNSApi/AxiNSIO.cs @@ -736,6 +736,7 @@ public class AxiNSIO #endif } +#if UNITY_SWITCH bool CreateLoopDir(string path) { // 检查路径是否存在及其类型 @@ -783,7 +784,7 @@ public class AxiNSIO return false; return true; } - +#endif /// /// 解析路径并获取其所有父级目录(从直接父目录到根目录),并排除存储设备挂载根节点(如"save:"或"sd:")。 diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/Model/EmuCoreBinder.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/Model/EmuCoreBinder.cs index 95b3ae58..669e2756 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/Model/EmuCoreBinder.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/Model/EmuCoreBinder.cs @@ -21,6 +21,13 @@ public abstract class EmuCoreBinder : InternalEmuCoreBinder, IDeviceBinder where T : Enum { + /// + /// 蹇界暐杈撳叆璁惧鐨勭嫭鍗犲睘鎬 + /// false:鏍囪涓虹嫭鍗犵殑璁惧锛圗xclusive==true锛夊彧鑳界粦瀹氬埌涓涓帶鍒跺櫒涓 + /// true:璁惧鍙互琚粦瀹氬埌鎵鏈夋帶鍒跺櫒涓婏紝鏃犺璁惧鐨勭嫭鍗犲睘鎬 + /// + protected virtual bool IgnoreInputDeviceExclusive => false; + //姣忎竴涓疄渚嬩唬琛ㄤ竴涓搴旀ā鎷熷櫒骞冲彴鐨勬帶鍒跺櫒绱㈠紩 List m_controllerBinders = new List(); @@ -37,7 +44,7 @@ public abstract class EmuCoreBinder : InternalEmuCoreBinder, { foreach (var binding in m_controllerBinders) { - if (device.Exclusive && GetRegistedBinder(device) != null) continue; + if (!CheckDeviceCanBind(device)) break; binding.RegistInputDevice(device); } @@ -64,11 +71,20 @@ public abstract class EmuCoreBinder : InternalEmuCoreBinder, { foreach (var binding in m_controllerBinders) { - if (connectDevice.Exclusive && GetRegistedBinder(connectDevice) != null) continue; + if (!CheckDeviceCanBind(connectDevice)) return; binding.RegistInputDevice(connectDevice); } } + private bool CheckDeviceCanBind(InputDevice_D device) + { + if (IgnoreInputDeviceExclusive) return true; + if (!device.Exclusive) return true; + + //褰撲竴涓緭鍏ヨ澶囩殑Exclusive涓簍rue鏃讹紝鍙兘缁戝畾鍒颁竴涓帶鍒跺櫒 + return GetRegistedBinder(device) == null; + } + private void InputDevicesMgr_OnDeviceLost(InputDevice_D lostDevice) { foreach (var binding in m_controllerBinders) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/XMBKeyBinding.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/XMBKeyBinding.cs index 636ac49b..bf83386b 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/XMBKeyBinding.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/XMBKeyBinding.cs @@ -1,10 +1,12 @@ 锘縰sing AxibugEmuOnline.Client.InputDevices; using AxibugProtobuf; +using static AxibugEmuOnline.Client.NesControllerMapper; namespace AxibugEmuOnline.Client { public class XMBKeyBinding : EmuCoreBinder { + protected override bool IgnoreInputDeviceExclusive => true; public override RomPlatformType Platform => RomPlatformType.Invalid; public override int ControllerCount => 2; @@ -39,78 +41,122 @@ namespace AxibugEmuOnline.Client } public override void Bind(DualShockController_D device, ControllerBinder controller) { - controller.SetBinding(EnumCommand.Back, device.Circle, 0); - controller.SetBinding(EnumCommand.Enter, device.Cross, 0); - controller.SetBinding(EnumCommand.OptionMenu, device.Options, 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); + switch (controller.ControllerIndex) + { + case 0: + controller.SetBinding(EnumCommand.Back, device.Circle, 0); + controller.SetBinding(EnumCommand.Enter, device.Cross, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.Options, 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); + 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: + controller.SetBinding(EnumCommand.OptionMenu, device.TouchpadBtn, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.R3, 1); + break; + } } public override void Bind(GamePad_D device, ControllerBinder controller) { - controller.SetBinding(EnumCommand.Back, device.East, 0); - controller.SetBinding(EnumCommand.Enter, device.South, 0); - controller.SetBinding(EnumCommand.OptionMenu, device.Start, 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); + switch (controller.ControllerIndex) + { + case 0: + controller.SetBinding(EnumCommand.Back, device.East, 0); + controller.SetBinding(EnumCommand.Enter, device.South, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.Start, 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: + controller.SetBinding(EnumCommand.OptionMenu, device.RightStickPress, 0); + break; + } - 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); } public override void Bind(PSVController_D device, ControllerBinder controller) { - controller.SetBinding(EnumCommand.Back, device.Circle, 0); - controller.SetBinding(EnumCommand.Enter, device.Cross, 0); - controller.SetBinding(EnumCommand.OptionMenu, device.Start, 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); + switch (controller.ControllerIndex) + { + case 0: + controller.SetBinding(EnumCommand.Back, device.Circle, 0); + controller.SetBinding(EnumCommand.Enter, device.Cross, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.Start, 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: + controller.SetBinding(EnumCommand.OptionMenu, device.Triangle, 0); + break; + } - 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); } public override void Bind(XboxController_D device, ControllerBinder controller) { - controller.SetBinding(EnumCommand.Back, device.B, 0); - controller.SetBinding(EnumCommand.Enter, device.A, 0); - controller.SetBinding(EnumCommand.OptionMenu, device.Menu, 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); + switch (controller.ControllerIndex) + { + case 0: + controller.SetBinding(EnumCommand.Back, device.B, 0); + controller.SetBinding(EnumCommand.Enter, device.A, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.Menu, 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: + controller.SetBinding(EnumCommand.OptionMenu, device.RightStickPress, 0); + break; + } - 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); } public override void Bind(ScreenGamepad_D device, ControllerBinder controller) { - controller.SetBinding(EnumCommand.Back, device.BTN_A, 0); - controller.SetBinding(EnumCommand.Enter, device.BTN_B, 0); - controller.SetBinding(EnumCommand.OptionMenu, device.OPTION_1, 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); + switch (controller.ControllerIndex) + { + case 0: + controller.SetBinding(EnumCommand.Back, device.BTN_A, 0); + controller.SetBinding(EnumCommand.Enter, device.BTN_B, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.OPTION_1, 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.JOYSTICK.Down, 1); - controller.SetBinding(EnumCommand.SelectItemLeft, device.JOYSTICK.Left, 1); - controller.SetBinding(EnumCommand.SelectItemRight, device.JOYSTICK.Right, 1); - controller.SetBinding(EnumCommand.SelectItemUp, device.JOYSTICK.Up, 1); + controller.SetBinding(EnumCommand.SelectItemDown, device.JOYSTICK.Down, 1); + controller.SetBinding(EnumCommand.SelectItemLeft, device.JOYSTICK.Left, 1); + controller.SetBinding(EnumCommand.SelectItemRight, device.JOYSTICK.Right, 1); + controller.SetBinding(EnumCommand.SelectItemUp, device.JOYSTICK.Up, 1); + break; + case 1: + controller.SetBinding(EnumCommand.OptionMenu, device.HOME, 0); + break; + } } public override void Bind(SwitchJoyCon_D device, ControllerBinder controller) { @@ -131,7 +177,7 @@ namespace AxibugEmuOnline.Client controller.SetBinding(EnumCommand.SelectItemUp, device.LeftStick.Up, 1); break; case 1://娓告垙涓璘I鎺у埗 - controller.SetBinding(EnumCommand.OptionMenu, device.Y, 0); + controller.SetBinding(EnumCommand.OptionMenu, device.RightStickPress, 0); break; } } diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/InputControls/Stick_C.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/InputControls/Stick_C.cs index 023b1146..72341190 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/InputControls/Stick_C.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/InputControls/Stick_C.cs @@ -18,19 +18,21 @@ namespace AxibugEmuOnline.Client.InputDevices { var axis = GetVector2(); - Up.m_performing = axis.y > 0f; + var dir = GetDirection(axis, 0.15f); + Up.m_performing = dir == Direction.Up; Up.Update(); - Down.m_performing = axis.y < 0f; + Down.m_performing = dir == Direction.Down; Down.Update(); - Left.m_performing = axis.x < 0f; + Left.m_performing = dir == Direction.Left; Left.Update(); - Right.m_performing = axis.x > 0f; + Right.m_performing = dir == Direction.Right; Right.Update(); } + public class VirtualButton : InputControl_C { @@ -53,5 +55,66 @@ namespace AxibugEmuOnline.Client.InputDevices return Performing ? 1 : 0; } } + + enum Direction + { + None, + Up, + Down, + Left, + Right + } + + static Direction GetDirection(Vector2 input, float deadzone) + { + // 妫鏌ユ鍖猴細濡傛灉鐐瑰湪姝诲尯鍗婂緞鍐咃紝杩斿洖鏃 + if (input.magnitude <= deadzone) + { + return Direction.None; + } + + // 鏍囧噯鍖栧悜閲忥紙纭繚鍦ㄥ崟浣嶅渾涓婏級 + Vector2 normalized = input.normalized; + + // 璁$畻鐐逛笌鍥涗釜鏂瑰悜鍩哄噯鍚戦噺鐨勭偣绉 + float dotUp = Vector2.Dot(normalized, Vector2.up); // (0, 1) + float dotDown = Vector2.Dot(normalized, Vector2.down); // (0, -1) + float dotRight = Vector2.Dot(normalized, Vector2.right); // (1, 0) + float dotLeft = Vector2.Dot(normalized, Vector2.left); // (-1, 0) + + // 鎵惧嚭鏈澶х偣绉搴旂殑鏂瑰悜 + Direction bestDirection = Direction.None; + float maxDot = -1f; // 鍒濆鍖栦负鏈灏忓 + + // 妫鏌ヤ笂鏂瑰悜 + if (dotUp > maxDot) + { + maxDot = dotUp; + bestDirection = Direction.Up; + } + + // 妫鏌ヤ笅鏂瑰悜 + if (dotDown > maxDot) + { + maxDot = dotDown; + bestDirection = Direction.Down; + } + + // 妫鏌ュ彸鏂瑰悜 + if (dotRight > maxDot) + { + maxDot = dotRight; + bestDirection = Direction.Right; + } + + // 妫鏌ュ乏鏂瑰悜 + if (dotLeft > maxDot) + { + bestDirection = Direction.Left; + } + + return bestDirection; + } + } }