Author Topic: UIInput EventDelegate.Add onSelect/onDeselect?  (Read 4663 times)

petrs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
UIInput EventDelegate.Add onSelect/onDeselect?
« on: May 09, 2014, 02:56:42 PM »
Hi,

How on earth can you set an onSelect or onDeselect EventDelegate (via EventDelegate.Add ())?

Basically I'm trying to simply detect focus on or focus off a dynamically created UIInput, hence the need for using EventDelegate.Add. Currently there are no onSelect or onDeselect defines for UIInput.

Petr

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput EventDelegate.Add onSelect/onDeselect?
« Reply #1 on: May 09, 2014, 10:01:58 PM »
Er, you don't. EventDelegate is a class type. Your question is the equivalent of asking "how can you set onSelect using a List (via List.Add())?". It doesn't make much sense.

If you want to receive OnSelect, then do just that. Add an OnSelect function.
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.     void OnSelect (bool isSelected)
  6.     {
  7.         Debug.Log("Selection: " + isSelected);
  8.     }
  9. }
Now, if you want to trigger some remote function instead of writing a script... then attach UIEventTrigger, and you can do it via inspector or EventDelegate.Add(GetComponent<UIEventTrigger>().onSelect, YourFunction);

petrs

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UIInput EventDelegate.Add onSelect/onDeselect?
« Reply #2 on: May 10, 2014, 01:10:36 PM »
I guess I really meant that onSelect and onDeselect should be added to UIInput's default delegates along with onChange, onSubmit and onValidate. (Or onGainFocus and onLoseFocus)

There seem to be many threads asking a similar thing. Writing an OnSelect handler is ok for simple apps, but if you are dealing with thousands of various groupings of NGUI components things get a bit convoluted. Sure I could change the original source code to support onSelect and onDeselect, but I'd rather not so I can upgrade easily. Currently I have written handler which suffices, but I feel its not the cleanest solution.

I think UIInput should have at least a default event delegate for losing focus, since this normally would trigger either a submit or erase action.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput EventDelegate.Add onSelect/onDeselect?
« Reply #3 on: May 11, 2014, 12:36:22 AM »
I'd rather not clutter the inspector any more than needed. You can already do that by attaching UIEventTrigger. It has all the notification types for your usage.