Support => NGUI 3 Support => Topic started by: SquigglyFrog on October 22, 2014, 03:00:33 PM
Title: help passing extra data using UIEventListener
Post by: SquigglyFrog on October 22, 2014, 03:00:33 PM
Ok, first I'll admit I am clearly a beginner when it comes to events and delegates and the like.. Currently I have a UIWidget with a button script attached, fileItemWidgets
What I'd really like to do is pass an INT into that OnAccountFileSelected.. everything I've tried so far hasn't worked, and what I want to end up with is something like this.
void OnAccountFileSelected(GameObject g, int ID)
{
print("Clicked filename: "+ ID.toString());
}
I checked the docs and I see this UIEventListener.FloatDelegate which would work, but i'm unsure how to actually use that and attach it to my buttons... suggestions / help is appreciated!
Title: Re: help passing extra data using UIEventListener
Post by: dilshod on October 23, 2014, 06:30:16 AM
Title: Re: help passing extra data using UIEventListener
Post by: SquigglyFrog on October 23, 2014, 08:59:17 AM
Well, that throws an error, probably though due to my lack of knowlege on events and listeners.. appreciate the help, will continue to dig into it and google some more..
Title: Re: help passing extra data using UIEventListener
Post by: dilshod on October 23, 2014, 11:31:28 AM
Well, that throws an error, probably though due to my lack of knowlege on events and listeners.. appreciate the help, will continue to dig into it and google some more..
My bad, updated the code above. You'll have more problems with anonymous functions, you'd better try this:
void Init(){
var listener = UIEventListener.Get(fileItemWidgets[5].gameObject);
listener.parameter=1234;
listener.onClick= OnAccountFileSelected;
}
void OnAccountFileSelected(GameObject g){
int ID =(int)UIEventListener.Get(g).parameter;
print("Clicked filename: "+ ID.ToString());
}
Title: Re: help passing extra data using UIEventListener
Post by: ArenMook on October 23, 2014, 03:41:59 PM
UIButton btn = GetComponent<UIButton>();
EventDelegate.Set(btn.onClick, delegate(){ Debug.Log("Inline delegates work fine too");});
Don't use UIEventListener when you already have a delegate provided by the button class.
Title: Re: help passing extra data using UIEventListener
Post by: SquigglyFrog on October 23, 2014, 04:03:35 PM
Hey thanks for that! The 2nd actually makes a lot more sense to me, and going back to the updated 1st example, I see how that works as well. I know this is a weak point of mine, and I truly appreciate both examples! Doesnt help that the doc has me on Pain Pills right now so the code this morning was in a bit of a haze. lol