Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Time in seconds from last click to event raise.
- /// </summary>
- [SerializeField]
- public float ClickDelay = 0.1f;
- int clicksCount = 0;
- IEnumerator clickDelayCoroutine;
- /// <summary>
- /// Process pointer click event.
- /// </summary>
- /// <param name="eventData">Event data.</param>
- public override void OnPointerClick(PointerEventData eventData)
- {
- if (!IsInteractable())
- {
- return;
- }
- onPointerClick.Invoke(eventData);
- if (eventData.button != PointerEventData.InputButton.Left)
- {
- return;
- }
- if (clickDelayCoroutine != null)
- {
- StopCoroutine(clickDelayCoroutine);
- }
- clicksCount = eventData.clickCount;
- clickDelayCoroutine = DelayClick();
- StartCoroutine(clickDelayCoroutine);
- }
- IEnumerator DelayClick()
- {
- yield return new WaitForSeconds(ClickDelay);
- RaiseClicks();
- }
- void RaiseClicks()
- {
- if (clicksCount == 1)
- {
- onClick.Invoke();
- onClickItem.Invoke(this);
- Select();
- }
- else if (clicksCount == 2)
- {
- onDoubleClick.Invoke(Index);
- }
- clicksCount = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement