4.6 GUI - Touch Position

Is there any way to get the position of a touch on GUI elements?

Say an image is touched by the player, and I’m observing the pressDown event, which would be the best way to fetch the screen position of that precise touch? Is there any way to get that info from the event itself?

Anyone?

eventData.touchPosition

How do I get to eventData from the editor/code when I observe such events from the editor itself?

not sure I follow, is this inside a custom editor script?

you can get events for your behaviour if you implement some interfaces:

UnityEngine.EventSystems.IPointerDownHander
UnityEngine.EventSystems.IPointerUpHander
UnityEngine.EventSystems.IPointerClickHander

there’s quite a few, once you implement the interface (only add the ones you need), you can add methods:

OnPointerDown(PointerEventData eventData)

Ah, ok.

My idea was to call a custom operation from the EventTrigger component on the editor itself and, instead of passing static parameters, using a dynamic one, but Vector2 is not allowed so I will have to manually code on the script.

Thanks a lot.

Edit: Picture it as a new way of declaring the signature of allowed functions, like MyFunction(bool), MyFunction(int), MyFunction(string) and so on, to MyFunction(Vector2, bool), etc., and on the editor, you are allowed to only set the second parameter, since you will be receiving automatically the value for the first Vector 2 paratemer.

Any chance for adding an event to the IEventSystemHandler interface? Say, like: event Action<UIEventType, BaseEventData> OnUIEvent, where UIEventType is an enum for the actions defined in the EventTrigger class? (Deselect, …, PointerDown, etc.)

I see there is another thread about this: Why can't we just have events? ( Detecting Clicks ) - Unity Engine - Unity Discussions

So, my question is: how can I get the touch position from an existing EventTrigger without having to create my own UI control from the scracth with a custom editor script?

Using uGUI 4.6 I have added an image to a canvas and then attached an event trigger to the image for the PointerDown event, that calls an operation OnFoo() of some script of the game object named Foo.

The issue that I see with this rationale is that there is no way to fetch the touch position of the event, since it is only notifying the game object that the event occurred and only static data is passed to it, like bool, int, float, string or none.

So, basically, what I want is a way to know where exaclty the image is being touched by the player without having to query each finger on a specific zone.

For what I can see on the event trigger class definition, that information is stored but neither exposed nor notified.

So, how can I fetch that info from the event trigger without having to create a custom image element for the editor?

Could anyone on the Unity Team reply, please?

Is querying Input.Touch[ ] and comparing it with the UI element’s rect the only way to achieve this?