Yea, this one is a bit tricky to explain clearly. What it boils down to is that EventDelegate doesn't support default parameters or intentionally passing null.
I'll do my best to explain fully. There are 2 cases. 1:
You have a method that takes a parameter that is a reference type deriving from System.object. e.g.
public void DoSomething ( Action onFinished )
You want to call this method with an EventDelegate on a UIButton.
You want to pass null for onFinished
You assign the relevant object to the EventDelegate.
You want to pass null so you don't specify the Arg0 target.
An exception will occur because the parameter that actually get's used will be either
or
(UnityEngine.Object) null
instead of
.
Supporting this would mean doing something like I posted above. At the end of EventDelegate.Parameter.value:
if ( !expectedType.IsValueType ) return System.Convert.ChangeType(null, expectedType);
return obj;
2:
You have a method that has a default value for the parameter. e.g.
public void DoSomething ( int index = 0 )
You want to call this method with an EventDelegate on a UIButton.
You want to not pass the int and let it use the default value.
You assign the relevant object to the EventDelegate.
You don't want to specify the argument, so you don't specify the Arg0 target.
An exception will occur.
I think to support this you'd have to do a little more reflection to see if the method has default parameters and if it does, invoke the method in a slightly different way.
http://stackoverflow.com/questions/2421994/invoking-methods-with-optional-parameters-through-reflectionThese can be worked around with an overload for the method, but I wanted to point them out in case you want to support the scenarios. The first one seems very straight forward, though the second one may or may not be worth the effort.