- Home /
Handle Mouse/Touch pan, zoom and click
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 action.
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)
All works well and in this way I can handle when do something.
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
On Mac/Mouse all works great! :D
On smartphone/Touch I can't click on nothing and only Pan 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