FBSwipe.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using UnityEngine;
  3. namespace FBInput
  4. {
  5. public class FBSwipe : AbstractTouchElement
  6. {
  7. public Vector2 Direction { get; private set; }
  8. protected override void OnTouchDown(Vector2 touchPosition)
  9. {
  10. this._touchStartPosition = touchPosition;
  11. this._timeOnTouchDown = Time.time;
  12. }
  13. protected override void OnTouchUp(Vector2 touchPosition)
  14. {
  15. Vector2 vector = touchPosition - this._touchStartPosition;
  16. bool flag = vector.sqrMagnitude >= this.MinTriggerDistance * this.MinTriggerDistance;
  17. bool flag2 = Time.time - this._timeOnTouchDown <= this.MaxTriggerTime;
  18. this.Direction = ((!flag || !flag2) ? Vector2.zero : vector.normalized);
  19. }
  20. protected override bool TestTouchArea(Vector2 screenPosition)
  21. {
  22. return screenPosition.x < (float)UITools.ScreenWidth / 2f;
  23. }
  24. private readonly float MinTriggerDistance = 20f;
  25. private readonly float MaxTriggerTime = 0.5f;
  26. private Vector2 _touchStartPosition;
  27. private float _timeOnTouchDown;
  28. }
  29. }