Seeking "hack" ideas to deal with touch display &q

This may be a little difficult to explain but I’ll have a go.

I’m developing something that will use a 3M 17" touch display and it seems to have a “feature” that is incompatable with the way Unity deals with RepeatButton().

I have a number of buttons that pan/rotate the camera, handled generally as

function OnGUI() {
if (GUI.RepeatButton(buttonrect,buttonicon)) {
// do the navigation
}
}

There is a subtle difference between a mouse driven system and a touch display. In the former when the mouse button is pressed the mouse is always/already in the right location. But on a touch display when it is touched the mouse position “jumps” to the new position. What I’m getting using RepeatButton() is sometimes the last button pressed because that is where the mouse was. I’m imagining the mouse position update is occurring after the mouse down event … most likely a bug with the touch display drivers. Note it isn’t consistent, happens perhaps 30% of the time.

Hope that was clear … anyone have an idea on a work around, hacks welcome.

Hi Paul,

Here’s an extended button class I wrote a while back the gives an EventType return, rather than a bool.
Maybe you could experiment with catching the mousedown event, or checking against the hot control etc.

Let me know if you need any help.

C#

using UnityEngine;
public class HoverButtonScript : MonoBehaviour
{
    static int HoverButtonHash = "HoverButton".GetHashCode();
    private Rect HoverButtonRect = new Rect(100, 100, 100, 100);
    void OnGUI()
    {
        switch (HoverButton(HoverButtonRect, new GUIContent("HoverButton"), "button"))
        {
            case EventType.mouseDown:
                Debug.Log("MouseDown");
                break;
            case EventType.mouseUp:
                Debug.Log("MouseUp");
                break;
            case EventType.mouseDrag:
                HoverButtonRect.x = Input.mousePosition.x - (HoverButtonRect.width / 2);
                HoverButtonRect.y = (Screen.height - Input.mousePosition.y) - (HoverButtonRect.height / 2);
                break;
            case EventType.mouseMove:
                GUI.Button(new Rect(HoverButtonRect.x + 100, HoverButtonRect.y, 50, 50), "Mouse\nis Over");
                break;
        }
    }
    public static EventType HoverButton(Rect position, GUIContent content, GUIStyle style)
    {
        int controlID = GUIUtility.GetControlID(HoverButtonHash, FocusType.Native);
        switch (Event.current.GetTypeForControl(controlID))
        {
            case EventType.mouseDown:
                if (position.Contains(Event.current.mousePosition))
                {
                    GUIUtility.hotControl = controlID;
                    Event.current.Use();
                    return EventType.mouseDown;
                }
                break;
            case EventType.mouseUp:
                if (GUIUtility.hotControl != controlID)
                    return EventType.ignore;
                GUIUtility.hotControl = 0;
                Event.current.Use();
                if (position.Contains(Event.current.mousePosition))
                    return EventType.mouseUp;
                else
                    return EventType.ignore;
            case EventType.mouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    Event.current.Use();
                    return EventType.mouseDrag;
                }
                else
                    return EventType.ignore;
            case EventType.repaint:
                style.Draw(position, content, controlID);
                if (position.Contains(Event.current.mousePosition))
                    return EventType.mouseMove;
                else
                    return EventType.repaint;
        }
        if (position.Contains(Event.current.mousePosition))
            return EventType.mouseMove;
        else
            return EventType.ignore;
    }
}

Hey Paul,

I am working with a Lumio touch panel connected to a win7 box and I am encountering the same issue you described. I am currently working on finding a hack to solve but have so far not had any luck.

I am wondering if you ever fixed this or found a workaround?

I am currently down a rabbit hole involving GUILayout.Labels masquerading as Buttons with dynamically positioned and sized Rects (GUILayoutUtility.GetLastRect()) that watch for Input.GetMouseButtonDown(0) Input.GetMouseButton(0) then read Event.current.mousePosition to check for a hit. So far not really working and I suspect timing issues related to reading Input or Event.current from OnGUI or some such madness.

Would love some tips if you solved this.
:slight_smile: