JetCharacterInput.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. namespace JTSystems
  6. {
  7. public abstract class JetCharacterInput : MonoBehaviour
  8. {
  9. public delegate void SendInput(Vector3 input);
  10. public SendInput sendInput;
  11. [SerializeField] private UnityEvent onMousePressed;
  12. [SerializeField] private MouseDragEvent onMouseDragged;
  13. [SerializeField] private UnityEvent onMouseReleased;
  14. protected Vector3 mouseDragVector;
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. }
  19. // Update is called once per frame
  20. void Update()
  21. {
  22. ManageInput();
  23. }
  24. protected void ManageInput()
  25. {
  26. if (Input.GetMouseButtonDown(0))
  27. OnMousePressed();
  28. else if (Input.GetMouseButton(0))
  29. OnMouseDragged();
  30. else if (Input.GetMouseButtonUp(0))
  31. OnMouseReleased();
  32. }
  33. protected virtual void OnMousePressed()
  34. {
  35. onMousePressed?.Invoke();
  36. }
  37. protected virtual void OnMouseDragged()
  38. {
  39. onMouseDragged?.Invoke(mouseDragVector);
  40. }
  41. protected virtual void OnMouseReleased()
  42. {
  43. onMouseReleased?.Invoke();
  44. }
  45. }
  46. [System.Serializable]
  47. public class MouseDragEvent : UnityEvent<Vector3>
  48. {
  49. }
  50. }