AutoClick.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. namespace SC.XR.Unity.Module_InputSystem {
  5. public class AutoClick : PointerHandler {
  6. public float autoClickTime = 3;
  7. Coroutine coroutineAddKey;
  8. bool isAddKeyFinish = false;
  9. public override void OnPointerEnter(PointerEventData eventData) {
  10. StartCountDown((eventData as SCPointEventData), autoClickTime);
  11. }
  12. public override void OnPointerDown(PointerEventData eventData) {
  13. StopCountDown((eventData as SCPointEventData));
  14. }
  15. public override void OnPointerExit(PointerEventData eventData) {
  16. StopCountDown((eventData as SCPointEventData));
  17. }
  18. void StartCountDown(SCPointEventData scData, float time) {
  19. if(scData == null)
  20. return;
  21. StopCountDown(scData);
  22. coroutineAddKey = StartCoroutine(AddKey(InputKeyCode.Enter, InputKeyState.DOWN, scData,time));
  23. scData.inputDevicePartBase.detectorBase.pointerBase.cursorBase.StartGazeAnimation(time);
  24. }
  25. void StopCountDown(SCPointEventData scData) {
  26. if(scData == null)
  27. return;
  28. if(coroutineAddKey != null)
  29. StopCoroutine(coroutineAddKey);
  30. scData.inputDevicePartBase.detectorBase.pointerBase.cursorBase.StopGazeAnimation();
  31. if(isAddKeyFinish) {
  32. isAddKeyFinish = false;
  33. StartCoroutine(AddKey(InputKeyCode.Enter, InputKeyState.UP, scData,0.5f));
  34. }
  35. }
  36. IEnumerator AddKey(InputKeyCode keycode, InputKeyState state, SCPointEventData scData, float time) {
  37. yield return new WaitForSeconds(time);
  38. scData.inputDevicePartBase.inputDataBase.inputKeys.InputDataAddKey(keycode, state);
  39. isAddKeyFinish = true;
  40. }
  41. }
  42. }