PlayerInputComponent.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using UnityEngine;
  2. using UnityEngine.InputSystem;
  3. public class PlayerInputComponent : MonoBehaviour
  4. {
  5. public Vector2 MoveInput { get; private set; }
  6. public Vector2 LastMoveInput { get; private set; }
  7. public Vector2 CameraInput { get; private set; }
  8. public Vector2 mousePosInput { get; private set; }
  9. public Vector2 touch0Input { get; private set; }
  10. public Vector2 touch1Input { get; private set; }
  11. public bool JumpInput { get; private set; }
  12. public bool HasMoveInput { get; private set; }
  13. public bool isPressDown { get; private set; }
  14. public void OnMoveEvent(InputAction.CallbackContext context)
  15. {
  16. Vector2 moveInput = context.ReadValue<Vector2>();
  17. bool hasMoveInput = moveInput.sqrMagnitude > 0.0f;
  18. if (HasMoveInput && !hasMoveInput)
  19. {
  20. LastMoveInput = MoveInput;
  21. }
  22. MoveInput = moveInput;
  23. HasMoveInput = hasMoveInput;
  24. }
  25. public void OnLookEvent(InputAction.CallbackContext context)
  26. {
  27. CameraInput = context.ReadValue<Vector2>();
  28. //Debug.Log(CameraInput);
  29. }
  30. public void OnTouch0Event(InputAction.CallbackContext context)
  31. {
  32. touch0Input = context.ReadValue<Vector2>();
  33. }
  34. public void OnTouch1Event(InputAction.CallbackContext context)
  35. {
  36. touch1Input = context.ReadValue<Vector2>();
  37. }
  38. public void OnJumpEvent(InputAction.CallbackContext context)
  39. {
  40. if (context.started || context.performed)
  41. {
  42. JumpInput = true;
  43. }
  44. else if (context.canceled)
  45. {
  46. JumpInput = false;
  47. }
  48. }
  49. public void OnUIRotEvent(InputAction.CallbackContext context)
  50. {
  51. mousePosInput = context.ReadValue<Vector2>();
  52. }
  53. public void OnPressDownEvent(InputAction.CallbackContext context)
  54. {
  55. if (context.started || context.performed)
  56. {
  57. isPressDown = true;
  58. }
  59. else if (context.canceled)
  60. {
  61. isPressDown = false;
  62. }
  63. }
  64. public void InputReset()
  65. {
  66. MoveInput = Vector2.zero;
  67. CameraInput = Vector2.zero;
  68. JumpInput = false;
  69. touch0Input = Vector2.zero;
  70. touch1Input=Vector2.zero;
  71. }
  72. }