no info, no examples on this, no help…
does anyone know how this component work ?
I’d be interrested in it for getting clicks from a canvas…
thanks
no info, no examples on this, no help…
does anyone know how this component work ?
I’d be interrested in it for getting clicks from a canvas…
thanks
Sometimes old versions of the manual have the pages you seek:
Here is a handy function I use often:
protected void addEventTrigger(EventTrigger eventTrigger, EventTriggerType type, UnityEngine.Events.UnityAction<BaseEventData> call)
{
EventTrigger.Entry entry = new EventTrigger.Entry();
entry.eventID = type;
entry.callback.AddListener(call);
eventTrigger.triggers.Add(entry);
}
// usage
addEventTrigger(GetComponent<EventTrigger>(), EventTriggerType.PointerDown, OnPointerDown);
Thanks @_geo1 for this answer
Yes triggers are candies when using scripting.
However i was not talking about those ones but about those ones:
the component sounds good for what i need but there’s no way to make it call any of the GO’s method…
So i got 2 conclusions:
Any idea ?
thanks and happy unitying !
okay… i answer to myself…
This component reacts to only UI clickable elements ( like an image or raw image ) whith the ‘clickable’ flag active.
It appears that no canva is able to catch and dispatch events… this is too bad as this means
that no events can be raised without some UI content…
Now whith an image UI, not set and with a color with alpha=0, the event trigger works as intended
Happy unitying !
Oh, I did not know you were referring to adding the handlers in the inspector.
The script I posted uses the very same component. The only difference is that the handlers are added via script. The culprit was (as you identified correctly) the fact that there was nothing for the GraphicsRaycaster to hit. As the name suggests it will trigger on anything which derives from Graphic.
To fake a clickable area I have another handy component for you (to avoid that alpha zero image trickery). Using this you can also implement custom shapes like circles, stars, … .
using UnityEngine;
using UnityEngine.UI;
public class Imaginary : MaskableGraphic
{
public override bool Raycast(Vector2 sp, Camera eventCamera)
{
// This just checks if the raycast hits the rect but you can add any custom shape or criteria here.
return base.Raycast(sp, eventCamera);
}
protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
}
}
Cheers!