AutoClick.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. namespace SC.InputSystem {
  6. public class AutoClick : PointerHandlers {
  7. public float autoClickTime = 3;
  8. Coroutine coroutineAddKey;
  9. bool isAddKeyFinish = false;
  10. public override void OnSCPointerEnter(InputDevicePartBase part, SCPointEventData eventData) {
  11. part.inputDeviceUIBase.model.lineIndicate.focus.endOfPointWhenTarget.AutoClickAnimationStart(autoClickTime);
  12. coroutineAddKey = StartCoroutine(AddKey(part, eventData));
  13. }
  14. public override void OnSCPointerDown(InputDevicePartBase part, SCPointEventData eventData) {
  15. part.inputDeviceUIBase.model.lineIndicate.focus.endOfPointWhenTarget.AutoClickAnimationStop();
  16. StopCoroutine(coroutineAddKey);
  17. if(isAddKeyFinish) {
  18. isAddKeyFinish = false;
  19. part.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.UP);
  20. }
  21. }
  22. public override void OnSCPointerExit(InputDevicePartBase part, SCPointEventData eventData) {
  23. part.inputDeviceUIBase.model.lineIndicate.focus.endOfPointWhenTarget.AutoClickAnimationStop();
  24. StopCoroutine(coroutineAddKey);
  25. if(isAddKeyFinish) {
  26. isAddKeyFinish = false;
  27. part.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.UP);
  28. }
  29. }
  30. IEnumerator AddKey(InputDevicePartBase part, SCPointEventData eventData) {
  31. yield return new WaitForSeconds(autoClickTime);
  32. part.inputDataBase.InputDataAddKey(InputKeyCode.Enter, InputKeyState.DOWN);
  33. isAddKeyFinish = true;
  34. }
  35. }
  36. }