prime31 / TouchKit

Gestures and input handling made sane for Unity
904 stars 137 forks source link

PopulateFromMouse is wrong with low-framerate and fast clicking #43

Closed MikeSchurman closed 8 years ago

MikeSchurman commented 8 years ago

With a low framerate it is possible for Input.GetMouseButtonUp and Input.GetMouseButtonDown to be true for the same frame. This causes populateFromMouse to begin a new touch before the last one has ended. This ultimately ends up with gestures having the same touch (id=0) inserted into their _trackingTouches list.

Near the top of internalUpdateTouches right after this line: _liveTouches.Add( _touchCache[0].populateFromMouse() ); I added the following code: mu += Input.GetMouseButtonUp(0) ? "u" : "-"; m += Input.GetMouseButton(0) ? "m" : "-"; md += Input.GetMouseButtonDown(0) ? "d" : "-"; history += _liveTouches.Count != 0 ? ((int)_liveTouches[0].phase).ToString() : "-"; Debug.Log(history + "\n" + mu + "\n" + m + "\n" + md);

This prints: ----------0112223------02111301303013-03--0110 ----------------u-----------u--u-u--u--u-----u ----------mmmmmm-------mmmmm-mm-m-mm--m---mmmm ----------d------------d-----d--d-d---d---d--d

As can be seen, at the end (0110 pattern) means you get "Begin Move Move Begin" for the fake touch which causes the issue.