Best practices to handle pan, zoom and click for both mouse/touch input

I’m working on a 2D turn based game and I’m in the condition to handle mouse and touch.

The game has an hexagonal map and requires pan, zoom and click actions.

Clicks
I started implementing click-actions to the desired objects (MapCell, …) using mainly Monobehaviours default methods as OnMouseUpAsButton, OnMouseDown, etc…
I decided to apply delegate-pattern so each object that requires an action, sends the event to its delegate who will do or not stuff. In this way all inputs converge to a TurnManager that, with a state machine, handles events in accordance to the current game state.

Example: MapCell.OnMouseUpAsButton() calls delegate.OnCellClick(MapCell)

:smile: All works well and in this way I can handle when do something.

Zoom and Pan
The problems arrived when I started to implement Zoom and Pan in the map. For these two actions, I had to avoid classic Monobehaviour method (OnMouseDown, OnMouseUpAsButton, …) and use LateUpdate.

So, I created a CameraHandler that in the LateUpdate uses:

  • HandleMouse()
  • HandleTouch()

and, using delegate pattern, evokes the actions below:

  • OnMapWillPan()
  • OnMapPan()
  • OnMapEnd()

To avoid Pan or Clicks over UI elements, TurnManager filters received events with EventSystem.current.IsPointerOverGameObject()

Problem
:smile: On Mac/PC/Mouse all works great!
:frowning: On smartphone/Touch I can’t click on nothing. Only pan action is working. (The debug on device is infernal because the lack of breakpoint or console)

Questions

  • Do you ever handle this things? How?
  • Which approach did you use?
  • What do you think I’m doing wrong?
  • Are there best practices to avoid problem like this and handle correctly crossplatform input?
  • Are there any good lecture/book for this argument?

PS: if needed I can show the code

This or some other similar asset may help: https://assetstore.unity.com/packages/tools/gui/in-game-debug-console-68068

  • That was in my web browsing cache, I’ve never used it… but think I’ve seen it recommended.

For IsPointerOverGameObject with touch, you must send the Touch.fingerID (if not doing so already).

OnMouseDown, etc… do not work with touch. I would suggest using the IPointer interfaces, which work for both touch and mouse.
You could also raycast, instead.

thanks methos, actually I don’t send anything to IsPointerOverGameObject. I’ll try to edit some part of my structure using the IPointer interfaces and I’ll let you know.

The assets seems very useful, I think I’ll use it