Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NGUI based buttons when using touchscreen #110

Merged
merged 1 commit into from
Dec 17, 2023
Merged

Conversation

drojf
Copy link
Contributor

@drojf drojf commented Nov 17, 2023

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:

private void OnClick()
{
    if (UICamera.currentTouchID == -1 && !(cooldown > 0f))
    {
...

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 mapping

I 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...

@drojf drojf merged commit 57c48c4 into mod Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant