private void OnMove(CallbackContext ctx) { if (dpadMovement || isPinning(state)) { return; } Vector2 input = ctx.ReadValue <Vector2>().normalized; if (input != Vector2.zero) { leftStickMovement = true; } else { leftStickMovement = false; } this.inputDirection = CalculateInputAngle(input.x, input.y); // Debug.Log($"inputDirection={inputDirection.ToString()}"); // Vector2 clampedVector = PixelClamp(RawVector(input)); Vector2 clampedVector = RawVector(input); this.move.x += clampedVector.x; this.move.y += clampedVector.y; }
private void StopMove(CallbackContext ctx) { dpadMovement = false; leftStickMovement = false; // Debug.Log($"stop moving: {move}, {dpadMovement}"); this.move = Vector2.zero; this.inputDirection = DEFAULT; }
private void OnDPadMove(CallbackContext ctx) { switch (state) { case State.DEFAULT: case State.WALKING: case State.JUMPING: case State.FALLING: if (leftStickMovement) { return; } dpadMovement = true; Vector2 input = ctx.ReadValue <Vector2>().normalized; this.inputDirection = CalculateInputAngle(input.x, input.y); Debug.Log($"inputDirection={inputDirection.ToString()}"); // Vector2 clampedVector = PixelClamp(RawVector(input)); Vector2 clampedVector = RawVector(input); (this.move.x, this.move.y) = (clampedVector.x, clampedVector.y); break; case State.CLIMBING_IDLE: case State.CLIMBING_UP: case State.CLIMBING_DOWN: break; case State.KNOCKED_BACK: break; case State.PINNING: break; case State.PIN_RELEASE: break; case State.P_RIGHT_UP: case State.P_RIGHT: case State.P_RIGHT_DOWN: case State.P_LEFT_UP: case State.P_LEFT: case State.P_LEFT_DOWN: break; default: throw new ArgumentOutOfRangeException(); } }
public static InputAngleState CalculateInputAngle(float x, float y) { InputAngleState angleState = DEFAULT; if (x >= 0.5 && y >= 0.5) { angleState = RIGHT_UP; } else if (x >= 0.5 && MagnitudeWithinRange(y)) { angleState = RIGHT; } else if (x >= 0.5 && y <= -0.5) { angleState = RIGHT_DOWN; } else if (MagnitudeWithinRange(x) && y <= -0.5) { angleState = DOWN; } else if (x <= -0.5 && y <= -0.5) { angleState = LEFT_DOWN; } else if (x <= -0.5 && MagnitudeWithinRange(y)) { angleState = LEFT; } else if (x <= -0.5 && y >= 0.5) { angleState = LEFT_UP; } else if (MagnitudeWithinRange(x) && y >= 0.5) { angleState = UP; } else { angleState = DEFAULT; } return(angleState); }
public static bool InputLeft(InputAngleState input) { return(input == LEFT || input == LEFT_UP || input == LEFT_DOWN); }
public static bool InputRight(InputAngleState input) { return(input == RIGHT || input == RIGHT_UP || input == RIGHT_DOWN); }