InputField onClick?

Inputfields are children of a button inside a scrolllist
I’d like the button to highlight when the inputfield is clicked on
Is there a callback to detect if an inputfield was clicked (not changed or end edited)?

It’s very easy.
Add a script on the Field that eats up OnClick for breakfast like so

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class ClickSelect : MonoBehaviour, IPointerClickHandler {
    public SessionButton button;
    public void OnPointerClick (PointerEventData eventData)
    {
        button.Select ();
    }
}
1 Like

You can also do this without a script by adding an *Event Trigger *component to the input field and using the Pointer Click event :smile:

6 Likes

look at you go all fancy with inbuilt components :wink:

1 Like

Are you saying that the EventTrigger performance has improved to the point that it should be used for single events?

As far as I was aware, EventTrigger (although simpler to use in the editor) shouldn’t be used unless you are using many events due to it polling/validating all events. For a single event, a single script is far better (imho)

3 Likes

Simon you’re saying the EvenTrigger component is a hog? I’ll keep my script until UT sheds some light on that.

1 Like

EventTrigger implements ALL interfaces (one or two is probably fine, LOTS of ET’s in a scene could clog things up). Things may have improved but you are generally swapping performance for simplicity. If you are comfortable doing scripts, I always recommend using the interface handlers.
Happy to be corrected if things have improved.

1 Like

Makes sense – doesn’t the c# compiler remove empty overrides?