forked from sin365/AxibugEmuOnline
修正摇杆(包括虚拟遥感)不能斜方向的问题
This commit is contained in:
parent
3d20db977a
commit
449ef4a597
@ -19,16 +19,16 @@ namespace AxibugEmuOnline.Client.InputDevices
|
|||||||
var axis = GetVector2();
|
var axis = GetVector2();
|
||||||
|
|
||||||
var dir = GetDirection(axis, 0.15f);
|
var dir = GetDirection(axis, 0.15f);
|
||||||
Up.m_performing = dir == Direction.Up;
|
Up.m_performing = (dir &= Direction.Up) > 0;
|
||||||
Up.Update();
|
Up.Update();
|
||||||
|
|
||||||
Down.m_performing = dir == Direction.Down;
|
Down.m_performing = (dir &= Direction.Down) > 0;
|
||||||
Down.Update();
|
Down.Update();
|
||||||
|
|
||||||
Left.m_performing = dir == Direction.Left;
|
Left.m_performing = (dir &= Direction.Left) > 0;
|
||||||
Left.Update();
|
Left.Update();
|
||||||
|
|
||||||
Right.m_performing = dir == Direction.Right;
|
Right.m_performing = (dir &= Direction.Right) > 0;
|
||||||
Right.Update();
|
Right.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,22 +56,21 @@ namespace AxibugEmuOnline.Client.InputDevices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Direction
|
[System.Flags]
|
||||||
|
enum Direction : byte
|
||||||
{
|
{
|
||||||
None,
|
None = 0,
|
||||||
Up,
|
Up = 1,
|
||||||
Down,
|
Down = 2,
|
||||||
Left,
|
Left = 4,
|
||||||
Right
|
Right = 8
|
||||||
}
|
}
|
||||||
|
|
||||||
static Direction GetDirection(Vector2 input, float deadzone)
|
static Direction GetDirection(Vector2 input, float deadzone)
|
||||||
{
|
{
|
||||||
// 检查死区:如果点在死区半径内,返回无
|
// 检查死区:如果点在死区半径内,返回无
|
||||||
if (input.magnitude <= deadzone)
|
if (input.magnitude <= deadzone)
|
||||||
{
|
|
||||||
return Direction.None;
|
return Direction.None;
|
||||||
}
|
|
||||||
|
|
||||||
// 标准化向量(确保在单位圆上)
|
// 标准化向量(确保在单位圆上)
|
||||||
Vector2 normalized = input.normalized;
|
Vector2 normalized = input.normalized;
|
||||||
@ -90,27 +89,27 @@ namespace AxibugEmuOnline.Client.InputDevices
|
|||||||
if (dotUp > maxDot)
|
if (dotUp > maxDot)
|
||||||
{
|
{
|
||||||
maxDot = dotUp;
|
maxDot = dotUp;
|
||||||
bestDirection = Direction.Up;
|
bestDirection |= Direction.Up;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查下方向
|
// 检查下方向
|
||||||
if (dotDown > maxDot)
|
if (dotDown > maxDot)
|
||||||
{
|
{
|
||||||
maxDot = dotDown;
|
maxDot = dotDown;
|
||||||
bestDirection = Direction.Down;
|
bestDirection |= Direction.Down;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查右方向
|
// 检查右方向
|
||||||
if (dotRight > maxDot)
|
if (dotRight > maxDot)
|
||||||
{
|
{
|
||||||
maxDot = dotRight;
|
maxDot = dotRight;
|
||||||
bestDirection = Direction.Right;
|
bestDirection |= Direction.Right;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查左方向
|
// 检查左方向
|
||||||
if (dotLeft > maxDot)
|
if (dotLeft > maxDot)
|
||||||
{
|
{
|
||||||
bestDirection = Direction.Left;
|
bestDirection |= Direction.Left;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bestDirection;
|
return bestDirection;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user