- Home /
[4.6 GUI] Source of event
When listening to an event, is it possible to know what object has raised it? The DF-GUI equivalent would be, for instance:
public void OnClick( dfControl source, dfMouseEventArgs args ){}
so I would know what GUI element was clicked.
Thanks for your help Lasse
Answer by orb · Sep 16, 2014 at 09:35 PM
PointerEventData has a raycast you can check for the trigger object:
void Test(PointerEventData data)
{
Debug.Log("Caller: "+data.pointerCurrentRaycast.go.name);
}
Thanks for the quick answer. However, the event system does not allow me to call a function with PointerEventData as a parameter. Strangly enough, it accepts its base class, BaseEventData.
They're actually interchangeable. The snippet above is working for me, but you may have to recast. A click with the mouse DOES actually send the PointerEventData, even if the EventTrigger claims it's BaseEventData. If you implement the interface in a script rather than using a trigger, you'll see that the mouse events (mostly) take PointerEventData as their sole argument.
If you're worried about assu$$anonymous$$g certain data structures to always be passed along even though the interface says otherwise, don't use the EventTrigger object. Just implement it in script to be on the safe side.
Ok thanks,
public void Test(BaseEventData data)
{
Debug.Log("Caller: " + data.selectedObject.name);
}
works for me.
Excellent! For some reason it wasn't completing selectedObject for me :)
Your answer
Follow this Question
Related Questions
When I pause my game and enable canvas and then resume my keyboard starts controlling the menu... 1 Answer
Example of setting up a button OnClick event via scripting? 2 Answers
Inventory GUI 0 Answers
Emulate RightArrow GUI Event 0 Answers
[4.6 - UI] How to call an event with button when the pointer is up the button image. 1 Answer