In C#/Unity, is there a way to pass more arguments to an event handler that were not specified in the delegate?
Assume that I cannot modify the delegate. (It comes from an external class.)
I need to be able to do this so I can unsubscribe from my handler later (onClick -= HandleClick somewhere else in the code).
Example:
delegate void A(str s);
event A onClick;
Awake() {
onClick += HandleClick;
}
void HandleOnClick(str s, int a) {
// How to get access to this second argument a here?
}
I know I can do the following:
int a = 10;
onClick += (s) => HandleOnClick(s, 10);
But this won't let me unregister the lambda (since it's an anonymous delegate) if I wire it up this way.