Fix NGUI based buttons when using touchscreen #110
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
A user reported that touchscreen doesn't work properly with the mod.
When you try to click a button on the title menu, it would flash as if you hovered over it, but would not do anything.
Only certain buttons (which turned out to be NGUI based) have this issue.
I tested and this issue happens even on the unmodded game (as I expected, as we have not modified input handling much in our mod)
Reason
This is because the input handling for NGUI based buttons in the game code first checks whether it is a left click, via the UICamera.currentTouchID variable with the code
UICamera.currentTouchID == -1
(-1 indicates mouse left click)For example:
However, when you touch a touchscreen, it returns a zero-or-higher number (eg 0,1,2,3 ...) representing the "fingerID". This causes the touch to be ignored.
See https://docs.unity3d.com/ScriptReference/Touch-fingerId.html
You're supposed to use this fingerID as in index to lookup the properties of the current touch
Fix
Changing to
UICamera.currentTouchID >= -1
should allow both mouse left clicks, and any touches to activate NGUI buttons.However there may be other places in the code which have similar problems, I haven't checked or tested it.
NGUI
UICamera.currentTouchID
mappingI think the mapping of the
UICamera.currentTouchID
variable (from NGUI) is something like:-3 = middle mouse
-2 = right mouse click
-1 = left mouse click
0 = touch index 0
1 = touch index 1
etc...