Advertisement
ilih

Untitled

Mar 4th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1.         /// <summary>
  2.         /// Time in seconds from last click to event raise.
  3.         /// </summary>
  4.         [SerializeField]
  5.         public float ClickDelay = 0.1f;
  6.  
  7.         int clicksCount = 0;
  8.  
  9.         IEnumerator clickDelayCoroutine;
  10.  
  11.         /// <summary>
  12.         /// Process pointer click event.
  13.         /// </summary>
  14.         /// <param name="eventData">Event data.</param>
  15.         public override void OnPointerClick(PointerEventData eventData)
  16.         {
  17.             if (!IsInteractable())
  18.             {
  19.                 return;
  20.             }
  21.  
  22.             onPointerClick.Invoke(eventData);
  23.  
  24.             if (eventData.button != PointerEventData.InputButton.Left)
  25.             {
  26.                 return;
  27.             }
  28.  
  29.             if (clickDelayCoroutine != null)
  30.             {
  31.                 StopCoroutine(clickDelayCoroutine);
  32.             }
  33.  
  34.             clicksCount = eventData.clickCount;
  35.  
  36.             clickDelayCoroutine = DelayClick();
  37.  
  38.             StartCoroutine(clickDelayCoroutine);
  39.         }
  40.  
  41.         IEnumerator DelayClick()
  42.         {
  43.             yield return new WaitForSeconds(ClickDelay);
  44.             RaiseClicks();
  45.         }
  46.  
  47.         void RaiseClicks()
  48.         {
  49.             if (clicksCount == 1)
  50.             {
  51.                 onClick.Invoke();
  52.                 onClickItem.Invoke(this);
  53.                 Select();
  54.             }
  55.             else if (clicksCount == 2)
  56.             {
  57.                 onDoubleClick.Invoke(Index);
  58.             }
  59.  
  60.             clicksCount = 0;
  61.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement