Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
CloseGets the number of consecutive times a down-up sequence was executed in a short amount of time with the same pointer ID and button.
There are two different formulas used to determine the value for clickCount.
If the event is a ClickEvent, a special data structure tracks
click counts for each pointer ID, and will use that click count when initializing the next click event:
- clickCount is incremented on PointerDownEvent.
- Time is measured between consecutive PointerDownEvents.
- The time limit is 0.5 seconds by default but can vary on some platforms.
- clickCount is reset whenever an event with a different pointer ID or button than the previous one is sent.
- clickCount is reset on PointerDownEvent if its target is not the same as the previous
PointerDownEvent.
If the event is not a ClickEvent, the value for clickCount does not follow a strict
formula, but rather it is determined by the active input framework and platform conventions.
The amount of time allowed and whether that time is measured between consecutive
PointerDownEvents or between a PointerUpEvent and the next
PointerDownEvent varies.
To remain consistent in your code, don't depend on clickCount for other events than
ClickEvent if possible. We recommend keeping track of click counts manually by
registering callbacks to PointerDownEvent and PointerUpEvent on the
IPanel.visualTree using the TrickleDown.TrickleDown phase to monitor all
incoming Panel events. The code below shows an example implementation.
using UnityEngine; using UnityEngine.UIElements;
public class ClickCountMonitor { public int ClickCount { get; private set; }
private float doubleClickTime; private int lastPointerId = -1; private int lastButton; private IEventHandler lastTarget; private float lastTime; public ClickCountMonitor(IPanel panel, float doubleClickTime = 0.5f) { this.doubleClickTime = doubleClickTime; panel.visualTree.RegisterCallback<PointerDownEvent>(e => { CheckResetConditions(e); ClickCount++; }, TrickleDown.TrickleDown); panel.visualTree.RegisterCallback<PointerUpEvent>(e => { CheckResetConditions(e); }, TrickleDown.TrickleDown); } private void CheckResetConditions(IPointerEvent e) { if (e.pointerId != lastPointerId || e.button != lastButton || ((EventBase)e).target != lastTarget || Time.time >= lastTime + doubleClickTime) ClickCount = 0; lastPointerId = e.pointerId; lastButton = e.button; lastTarget = ((EventBase)e).target; lastTime = Time.time; } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.