The Hedgehog Team Community

General Category => EasyTouch => Topic started by: arandono on May 17, 2018, 01:52:42 AM

Title: Quick Fix for EasyTouch Mouse Controls
Post by: arandono on May 17, 2018, 01:52:42 AM
I've been using the EasyTouch trackpad controls for desktop builds. Everything had been working well except for one thing that was causing problems. On Mac laptops, you can allow for tap-to-click gestures where you just lightly tap the touchpad without actually clicking the trackpad. This was causing issues on my desktop build because EasyTouch was registering a On_TouchStart event but not registering an On_TouchUp event. As a consequence, On_TouchDown was being called every frame after a tap-to-click event (even after the user had stopped touching the trackpad completely) which wouldn't stop until the next touch event occurred.

I did some Debuging and found that it only occurred in instances where OnMouseButtonDown and OnMouseButtonUp were called in the same frame. In this case, OnMouseButtonUp was called before On_TouchStart, so EasyTouch never received information that the touch event had ended.

I found a quick fix: in EasyTouch.Update Touches there's a code block
      
      else{
         int i=0;
         while (i<touchCount){
            fingers = input.GetMouseTouch(i,fingers) as Finger;
            fingers.touchCount = touchCount;
            i++;
         }         
      }

which I replaced with

  else if(!(Input.GetMouseButtonUp(0) && Input.GetMouseButtonDown(0))){
                int i=0;
                while (i<touchCount){
                    fingers = input.GetMouseTouch(i,fingers) as Finger;
                    fingers.touchCount = touchCount;
                    i++;
                }           
            }

This seemed to work. Haven't tested it thoroughly and if there's a better workaround, I'd love to hear it!