CompassButtonHandler.cs 739 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Events;
  4. using UnityEngine.EventSystems;
  5. using System.Collections;
  6. namespace CompassNavigatorPro {
  7. public class CompassButtonHandler : MonoBehaviour, IPointerDownHandler, IPointerUpHandler {
  8. public UnityAction actionHandler;
  9. Coroutine co;
  10. public void OnPointerDown (PointerEventData eventData) {
  11. if (co != null) {
  12. StopCoroutine (co);
  13. }
  14. co = StartCoroutine (ExecuteHandler ());
  15. }
  16. public void OnPointerUp (PointerEventData eventData) {
  17. if (co != null) {
  18. StopCoroutine (co);
  19. }
  20. }
  21. IEnumerator ExecuteHandler () {
  22. WaitForEndOfFrame w = new WaitForEndOfFrame ();
  23. while (true) {
  24. actionHandler ();
  25. yield return w;
  26. }
  27. }
  28. }
  29. }