Support => NGUI 3 Support => Topic started by: petrs on May 09, 2014, 02:56:42 PM
Title: UIInput EventDelegate.Add onSelect/onDeselect?
Post by: petrs 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
Title: Re: UIInput EventDelegate.Add onSelect/onDeselect?
Post by: ArenMook 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.
usingUnityEngine;
publicclass Test : MonoBehaviour
{
void OnSelect (bool isSelected)
{
Debug.Log("Selection: "+ isSelected);
}
}
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);
Title: Re: UIInput EventDelegate.Add onSelect/onDeselect?
Post by: petrs 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.
Title: Re: UIInput EventDelegate.Add onSelect/onDeselect?
Post by: ArenMook 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.