From baf2e5a8d6215e078a866c68fa98b23047f16144 Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Mon, 22 Sep 2025 17:11:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=BF=E5=85=8D=E4=BD=BF=E7=94=A8=E4=B8=89?= =?UTF-8?q?=E8=A7=92=E5=87=BD=E6=95=B0=E5=88=A4=E6=96=AD=E6=AD=BB=E5=8C=BA?= =?UTF-8?q?=20:D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Devices/InputControls/Stick_C.cs | 52 ++++++------------- 1 file changed, 16 insertions(+), 36 deletions(-) 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 8a960cd9..6634b23b 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 @@ -19,20 +19,20 @@ namespace AxibugEmuOnline.Client.InputDevices var axis = GetVector2(); var dir = GetDirection(axis, 0.15f); - Up.m_performing = (dir &= Direction.Up) > 0; + Up.m_performing = (dir & Direction.Up) > 0; Up.Update(); - Down.m_performing = (dir &= Direction.Down) > 0; + Down.m_performing = (dir & Direction.Down) > 0; Down.Update(); - Left.m_performing = (dir &= Direction.Left) > 0; + Left.m_performing = (dir & Direction.Left) > 0; Left.Update(); - Right.m_performing = (dir &= Direction.Right) > 0; + Right.m_performing = (dir & Direction.Right) > 0; Right.Update(); } - + public class VirtualButton : InputControl_C { @@ -68,49 +68,29 @@ namespace AxibugEmuOnline.Client.InputDevices 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) + //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) + // 标准化向量(确保在单位圆上) + Vector2 normalized = input.normalized; // 找出最大点积对应的方向 Direction bestDirection = Direction.None; - float maxDot = -1f; // 初始化为最小值 - // 检查上方向 - if (dotUp > maxDot) - { - maxDot = dotUp; - bestDirection |= Direction.Up; - } - + if (normalized.y > deadzone) bestDirection |= Direction.Up; // 检查下方向 - if (dotDown > maxDot) - { - maxDot = dotDown; - bestDirection |= Direction.Down; - } - + if (normalized.y < -1 * deadzone) bestDirection |= Direction.Down; // 检查右方向 - if (dotRight > maxDot) - { - maxDot = dotRight; - bestDirection |= Direction.Right; - } - + if (normalized.x > deadzone) bestDirection |= Direction.Right; // 检查左方向 - if (dotLeft > maxDot) - { - bestDirection |= Direction.Left; - } + if (normalized.x < -1 * deadzone) bestDirection |= Direction.Left; return bestDirection; }