MultiTapButton.cs 744 B

123456789101112131415161718192021222324252627282930
  1. namespace SRDebugger.UI.Controls
  2. {
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. public class MultiTapButton : UnityEngine.UI.Button
  6. {
  7. private float _lastTap;
  8. private int _tapCount;
  9. public int RequiredTapCount = 3;
  10. public float ResetTime = 0.5f;
  11. public override void OnPointerClick(PointerEventData eventData)
  12. {
  13. if (Time.unscaledTime - _lastTap > ResetTime)
  14. {
  15. _tapCount = 0;
  16. }
  17. _lastTap = Time.unscaledTime;
  18. _tapCount++;
  19. if (_tapCount == RequiredTapCount)
  20. {
  21. base.OnPointerClick(eventData);
  22. _tapCount = 0;
  23. }
  24. }
  25. }
  26. }