ButtonMouseSelector.cs 963 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using UnityEngine;
  3. namespace Rokid.UXR.Interaction {
  4. public class ButtonMouseSelector : MonoBehaviour, ISelector
  5. {
  6. public event Action WhenSelected;
  7. public event Action WhenUnselected;
  8. private bool isCanClick = true;
  9. public void setClickEnable(bool enable)
  10. {
  11. isCanClick = enable;
  12. }
  13. void Update()
  14. {
  15. if (!isCanClick)
  16. {
  17. return;
  18. }
  19. #if UNITY_EDITOR
  20. if (Input.GetKeyDown(KeyCode.KeypadEnter))
  21. {
  22. WhenSelected?.Invoke();
  23. }
  24. if (Input.GetKeyUp(KeyCode.KeypadEnter))
  25. {
  26. WhenUnselected?.Invoke();
  27. }
  28. #else
  29. if (Input.GetKeyDown(KeyCode.JoystickButton0))
  30. {
  31. WhenSelected?.Invoke();
  32. }
  33. if (Input.GetKeyUp(KeyCode.JoystickButton0))
  34. {
  35. WhenUnselected?.Invoke();
  36. }
  37. #endif
  38. }
  39. }
  40. }