MultiTapButton.cs 669 B

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