Multiple Event Handlers
From Pointui
We have built support in to allow multiple handlers to be assigned to a single event, mainly because it seemed like a cool thing to do, but we haven’t yet had a use for it – maybe you will.
Here is an example (notice the use of the “+=” operator):
class Example { Event OnDownloadComplete; void Start() { //set up two handlers for the event //both Handler1() and Handler2() will be called when the event is triggered OnDownloadComplete += Handler1; OnDownloadComplete += Handler2; } void Stop() { //remove the handlers OnDownloadComplete -= Handler1; OnDownloadComplete -= Handler2; } void Handler1() { } void Handler2() { } }
The use of the “=” assignment will clear out all handlers previously there and replace them with the single handler being assigned.
At this stage it’s not possible to clear multiple handlers other than using the “=” assignment or individually removing them with “-=”.
