Hi,
I'm trying to do this in a loop:
var ed
= new EventDelegate
(delegate() {
playButtonClicked(q.id);
});
playButton.onClick.Add(ed);
where playButton changes to a different gameObject (UIButton) each time, and q.id is a string that changes each time as well.
I'm trying to do this in a loop with 2 iterations. This doesn't appear to work -- when clicking the FIRST button, it actually activates the 2nd button's EventDelegate, even though its GameObject is completely inactive. I've verified this though logging the GetHashCode of the button, and logging when the delegate gets called (what its string param is set to and the hashcode of the button there too).
The solution is unfortunately to not use EventDelegate.Callback when doing multiple EventDelegates this way -- use Parameters:
var ed
= new EventDelegate
(this,
"playButtonClicked"); ed.parameters[0].value = q.id;
playButton.onClick.Add(ed);
This means we can't use anonymous function delegates (delegate()) or lambdas (() => {}) in EventDelegates until this is fixed.
Any thoughts?
Thanks.