123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using UnityEngine;
- using UnityEngine.InputSystem;
- public class PlayerInputComponent : MonoBehaviour
- {
- public Vector2 MoveInput { get; private set; }
- public Vector2 LastMoveInput { get; private set; }
- public Vector2 CameraInput { get; private set; }
- public Vector2 mousePosInput { get; private set; }
- public Vector2 touch0Input { get; private set; }
- public Vector2 touch1Input { get; private set; }
- public bool JumpInput { get; private set; }
- public bool HasMoveInput { get; private set; }
- public bool isPressDown { get; private set; }
- public void OnMoveEvent(InputAction.CallbackContext context)
- {
- Vector2 moveInput = context.ReadValue<Vector2>();
- bool hasMoveInput = moveInput.sqrMagnitude > 0.0f;
- if (HasMoveInput && !hasMoveInput)
- {
- LastMoveInput = MoveInput;
- }
- MoveInput = moveInput;
- HasMoveInput = hasMoveInput;
- }
- public void OnLookEvent(InputAction.CallbackContext context)
- {
- CameraInput = context.ReadValue<Vector2>();
- //Debug.Log(CameraInput);
- }
- public void OnTouch0Event(InputAction.CallbackContext context)
- {
- touch0Input = context.ReadValue<Vector2>();
- }
- public void OnTouch1Event(InputAction.CallbackContext context)
- {
- touch1Input = context.ReadValue<Vector2>();
- }
- public void OnJumpEvent(InputAction.CallbackContext context)
- {
- if (context.started || context.performed)
- {
- JumpInput = true;
- }
- else if (context.canceled)
- {
- JumpInput = false;
- }
- }
- public void OnUIRotEvent(InputAction.CallbackContext context)
- {
- mousePosInput = context.ReadValue<Vector2>();
- }
- public void OnPressDownEvent(InputAction.CallbackContext context)
- {
- if (context.started || context.performed)
- {
- isPressDown = true;
- }
- else if (context.canceled)
- {
- isPressDown = false;
- }
- }
- }
|