Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: mortennobel on October 20, 2013, 09:57:05 PM
-
I'm a little confused why event delegates now has to be methods on a MonoBehavior object. In my code I use something like
EventDelegate.Callback onChange = delegate {
// foo
};
EventDelegate.Add(slider.onChange, onChange);
However this now creates a event delegate which 'isValid' property returns false. The event delegate is added to the slider.onChange but is never invoked since it is invalid.
Is this "feature" intended?
-
Yes.
To save a delegate reference in Unity that has not been specified by code, the only way to do it is to have a reference to a MonoBehaviour, as well as a string for the function name. Given these two values it's possible to recover the delegate.
Delegates specified using inline functionality you're using are not possible to save, so they are incompatible with this system.
-
In my case I'm scripting the events runtime and don't need the events to be persistent.
I understand your argument though, but you suggest a warning if the target cannot be cast to MonoBehavior (EventDelegate.Set (line 130)).
-
That's a fair point. I'll add one.